Wednesday, September 28, 2011

Android Button Status test

Button style

Every Button is styled using the system's default button background, which is often different from one device to another and from one version of the platform to another. If you're not satisfied with the default button style and want to customize it to match the design of your application, then you can replace the button's background image with a state list drawable. A state list drawable is a drawable resource defined in XML that changes its image based on the current state of the button. Once you've defined a state list drawable in XML, you can apply it to your Button with the android:background attribute. For more information and an example, see State List Drawable.
Also see the Form Stuff tutorial for an example implementation of a button.
XML attributes
See Button Attributes, TextView Attributes, View Attributes

android_button.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
   
<item android:drawable="@drawable/android_pressed" android:state_pressed="true" />
   
<item android:drawable="@drawable/android_focused" android:state_focused="true" />
   
<item android:drawable="@drawable/android_normal" />
</selector>

res/layout/main.xml
  .....
    <Button
       
android:id="@+id/button"
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:padding="10dp"
       
android:background="@drawable/android_button" />
     ..... 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.