You don't have to put UI states and the image that makes it different from other buttons into the same drawable / image.

ImageButton can use two separate images: one is android:background and one is android:src. If you provide UI state feedback with one (the background), you can use a simple .png image for the other (the "src" one) to make buttons look different.

There is also a LayerList drawable that can combine multiple drawables into one, this might work too (although I haven't used it):

http://developer.android.com/guide/topics/resources/drawable-resource.html#LayerList

-- Kostya

26.01.2011 17:06, Samsung Galaxy пишет:
Hi, I am doing some thing stupid. Look to this XML file

<?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" />

         <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" />

         <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>

How i will refer my individual button to my android display ? right
now i have only one button.

<Button
  android:id="@+id/button"
           android:layout_width="325px"
           android:layout_height="400px"
           android:padding="10dp"
           android:background="@drawable/diffbutt" />

How i can make multiple<selector>  in an XML file and then in another
XML file refer each<selector>  to a particular button. i have 4
(press) x 4 (focus) x 4 (normal) images for each 4 buttons.


Atif



On Jan 26, 1:47 pm, Kostya Vasilyev<[email protected]>  wrote:
You need one XML file with<selector>, and several drawable files that
it would reference for individual states, for example, 3 PNGs or nine
patches.

26.01.2011 15:40, Samsung Galaxy пишет:









Hi,
I have 4 buttons. and right now i have this XML file to handle
pressed, focused and normal states of a button.
<?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>
do i have to make 4 XML files for each button or is there some way to
do it in one XML file ?? Right now i am referring this file to another
XML file.
<Button
          android:id="@+id/button"
          android:layout_width="325px"
          android:layout_height="400px"
          android:padding="10dp"
          android:background="@drawable/diffbutt" />
</LinearLayout>
Atif
On Jan 26, 1:10 pm, Samsung Galaxy<[email protected]>    wrote:
This tutorial is more helpful and I found what i want.
http://developer.android.com/resources/tutorials/views/hello-formstuf...
On Jan 26, 11:07 am, Kostya Vasilyev<[email protected]>    wrote:
Atif,
You don't need to replace the image from code when the user clicks on a
button - with a state list drawable this can be done entirely with
resources:
http://developer.android.com/guide/topics/resources/drawable-resource...
-- Kostya
26.01.2011 13:03, Atif Musaddaq пишет:
Hi, Guys
a Simple Question.
I have four buttons and I am using four images for each button. is
there any way to replace the image when user Click on the button. I
want to make them more interactive. Right now it
seems.................... boring when user click on it, no feedback to
the user.
Thanks in advance.
Atif
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--
Kostya Vasilyev -- WiFi Manager + pretty widget --http://kmansoft.wordpress.com
--
Kostya Vasilyev -- WiFi Manager + pretty widget --http://kmansoft.wordpress.com


--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to