The ToggleButton control has checked properties that are useful for function buttons to toggle state
Here is an example of the effect and layout of the phone's open Dtmftwelvekeydialer button
Activity_main.xml
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical"Android:paddingleft= "@dimen/activity_horizontal_margin"Android:paddingtop= "@dimen/activity_vertical_margin"Tools:context=". Mainactivity " > <ToggleButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:background= "@drawable/button_incall"Android:drawabletop= "@drawable/icon_keyboard_bg"Android:texton= "Keyboard"Android:textoff= "Keyboard"android:textsize= "32dip"Android:textcolor= "#FFFFFF" /> </LinearLayout>
Where Drawabletop refers to the Icon_keyboard_bg.xml
Icon_keyboard_bg.xml
<?XML version= "1.0" encoding= "Utf-8"?><selectorxmlns:android= "Http://schemas.android.com/apk/res/android"> <Itemandroid:state_pressed= "true"android:drawable= "@drawable/icon_keyboard_up_pressed" /> <Itemandroid:state_checked= "true"android:drawable= "@drawable/icon_keyboard_up" /> <Itemandroid:state_checked= "false"android:drawable= "@drawable/icon_keyboard_down" /> <Itemandroid:drawable= "@drawable/icon_keyboard_down" /></selector>
This allows you to switch between three different state images when the button is clicked.
1. Effect in the natural state
2. Press the button effect
3. Effect of attribute checked= "true"
The problem of internationalization should be paid attention to in actual use string, spacing, size should not be hard-coded