button click on picture Toggle Effect

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.