Click button font color, picture change, background change

Source: Internet
Author: User

Create the Color.xml file in the values directory first

<?xml version= "1.0" encoding= "Utf-8"?>  <resources>      <drawable name= "Red" > #f00 </ drawable>      <drawable name= "green" > #0f0 </drawable>      <drawable name= "Gray" > #ccc </ Drawable>  

Create a new drawable directory under RES and create a new btn_bg.xml and Btn_color.xml file with the following code:

Btn_bg.xml

1 <?xml version= "1.0" encoding= "Utf-8"?>  2 <selector xmlns:android= "/http Schemas.android.com/apk/res/android ">  3     <item android:state_window_focused=" false " Android:state_enabled= "true"  4         android:drawable= "@drawable/btn_test_normal"/>  5      <item android:state_enabled= "false" android:drawable= "@drawable/btn_test_normal"/>  6      <item android:state_pressed= "true" android:drawable= "@drawable/btn_test_press"/>  7      <item android:state_focused= "true"8 android:drawable= "@drawable/btn_test_normal"/>  9

Btn_color.xml

1     <?xml version= "1.0" encoding= "Utf-8"?>  2     <selector xmlns:android= "/http Schemas.android.com/apk/res/android ">  3         <item android:state_focused=" false "android:state _enabled= "true" android:state_pressed= "false"  4             android:color= "@drawable/red"/>   5         <item android:state_enabled= "false" android:color= "@drawable/gray"/>  6         <item android:state_pressed= "true" android:color= "@drawable/green"/>  7         <item Android:state_focused= "true"  android:color= "@drawable/red"/>  8     </selector>  

Using in layouts

1 <button  2         android:layout_width= "Wrap_content"  3         android:layout_height= "Wrap_content"  4         android:text= "Press text will change effect"  5         Android:textcolor= "@drawable/btn_color"  6         android:background= "@drawable/btn_bg"  7         />  

Click button font color, picture change, background change

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.