Android Studio Toggle Button
Activity_main.mxl
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:gravity="center"
android:background="@drawable/gradientsgreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".design15part15">
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:onClick="onDefaultToggleClick"
android:text="@string/togglebutton" />
<ToggleButton
android:id="@+id/toggleButton2"
android:layout_width="wrap_content"
android:layout_margin="15dp"
android:layout_height="wrap_content"
android:textOn=""
android:textOff=""
android:background="@drawable/toggle_selector"
android:onClick="onloveToggleClick"
android:text="@string/togglebutton2" />
</LinearLayout>
Android Studio Design Animation
Main_activity.kt
package com.designapp
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Toast
class design15part15 : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_design15part15)
}
fun onDefaultToggleClick(view : View) {
Toast.makeText(this, "DefaultToggle", Toast.LENGTH_SHORT).show()
}
fun onloveToggleClick(view : View) {
Toast.makeText(this, "CustomsToggle", Toast.LENGTH_SHORT).show()
}
}
Android Studio Design Animation
toggle_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false"
android:drawable="@drawable/ic_favorite_border_black_24dp"/>
<item android:drawable="@drawable/ic_favorite_black_24dp"
android:state_checked="true"/>
</selector>
0 Response to "Android Studio Toggle Button"
Post a Comment