button buttons picture toggle effect Settings.
Usually use the Picture button click event in the project, mostly use ImageButton. Here we use
Button's Click event, which is no longer set through Setbackgroundresource () during the switch of the picture
Click Effect. Instead, the transition effect is pre-set through. Xml. Here we are accustomed to put the. xml file under the Drawable folder.
The code is as follows:
XML file name here is Test_press.xml
1. Android:state_pressed= "true" for post-click Effects
2, android:state_focused= "true"
3, the last line <item android:drawable= "@drawable/ok"/>
is essential, otherwise it will cause confusion in the layout. In addition, the drawable of the bank is actually
The default display picture. So with this line of code, the above 2 can not be written. For the sake of the program
Integrity, we suggest or write it.
<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android "> <item android:drawable=" @drawable/ok_press "android:state_pressed=" true "/> <item android:drawable= "@drawable/ok" android:state_focused= "true"/> <item android:drawable= "@drawabl E/ok "/> </selector>
Settings for button buttons
Just set one step
android:background= "@drawable/test_press"
<button android:id= "@+id/button1" android:layout_width= "wrap_content" android:layout_height= "Wrap_ Content "android:background=" @drawable/test_press "/>
You only need to use the button's listener normally in the main code, and the click Effect will be switched automatically.
This article is from the "climb over the mountains to see the Sea" blog, please be sure to keep this source http://670176656.blog.51cto.com/4500575/1587852
button click on picture Toggle Effect