tags:

views:

55

answers:

2

<item android:state_focused="true" > 
    <shape> 
        <gradient 
            android:endColor="#FF9900" 
            android:startColor="#FF9966" 
            android:angle="270" /> 
        <stroke 
            android:width="3dp" 
            android:color="#CCCCCC" /> 
        <corners 
            android:radius="3dp" /> 
        <padding 
            android:left="10dp" 
            android:top="10dp" 
            android:right="10dp" 
            android:bottom="10dp" /> 
    </shape> 
</item> 

   <item>         
    <shape> 
        <gradient 
            android:endColor="#FFFFFF" 
            android:startColor="#FFFFFF" 
            android:angle="270" /> 
        <stroke 
            android:width="1dp" 
            android:color="#666666" /> 
        <corners 
            android:radius="1dp" /> 
        <padding 
            android:left="3dp" 
            android:top="3dp" 
            android:right="3dp" 
            android:bottom="3dp" /> 
    </shape> 
</item> 

The above is the code I have written for filling borders of Button with black color.The same code I was using for 3 buttons by setting as background.Now, when I click button1, red color appears and goes when I releases. But I want Red color to be visible, until I press next button. Though I release Button1 after press, Red color should be visible. But Red color should only disappear when I press any other button.
Can anyone help me in solving this issue?
Please anyone help me in sorting out this issue?
Thanks in Advance,

A: 

Try adding a state for android:state_selected

jqpubliq
android:state_selected has no effect. I added a separate tag for this along with android:state_pressed.Kindly give me any other solution
Android_programmer_camera
A: 

I am afraid you cannot complete your goal just through xml that defines button states. Because, AFAIK there is no state that defines button behavior after it was released (just normal, focused and pressed). Normal state is supposed.

But, you can do the following:

  • let's say that your original xml drawable is drawable A
  • define new xml drawable B, that has normal state defined as wanted red button
  • after user presses your button it will be red because drawable A says that
  • when user releases button, ensure it stays red through change of the drawable

    myButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.B));

  • when user presses another button revert it back to normal state through

    myButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.A));

Desiderio