Selector_button dosnt working on my buttons on android.how reslove?

Hello friends Stackoverflow. I wrote selector_button.xmlbelow to make my buttons more beautiful. But this does not affect my buttons. Where am I mistaken?

it selector_button.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >

     <!-- When clicked  -->
    <item android:state_pressed="true"
        android:state_selected="true" >
        <shape >
        <gradient        
            android:angle="90"        
            android:centerColor="@color/Lightgray"        
            android:endColor="@color/White"        
            android:startColor="@color/LightBlue"/>    
            <corners android:radius="12dip" />    
            <stroke        
                android:width="0dip"       
                 android:color="@color/LightBlue" />

         </shape>
    </item>
    <!-- When not clicked-->
      <item >
        <shape >
        <gradient        
            android:angle="90"        
            android:centerColor="#ff008888"        
            android:endColor="@color/LightBlue"        
            android:startColor="@color/Lightgray"/>    
            <corners android:radius="12dip" />    
            <stroke        
                android:width="0dip"       
                 android:color="@color/LightBlue" />
      </shape> 
</item>


</selector>
+3
source share
5 answers

I finally fixed the issue with friends guidance. I changed the code to this and worked as well.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >

     <!-- When clicked  -->
    <item android:state_pressed="true">
        <shape >
        <gradient        
            android:angle="90"        
            android:centerColor="@color/Lightgray"        
            android:endColor="@color/White"        
            android:startColor="@color/LightBlue"/>    
            <corners android:radius="12dip" />    
            <stroke        
                android:width="0dip"       
                 android:color="@color/LightBlue" />

         </shape>
    </item>
    <!-- When not clicked-->
      <item android:state_pressed="false" >
        <shape >
        <gradient        
            android:angle="90"        
            android:centerColor="#ff008888"        
            android:endColor="@color/LightBlue"        
            android:startColor="@color/Lightgray"/>    
            <corners android:radius="12dip" />    
            <stroke        
                android:width="0dip"       
                 android:color="@color/LightBlue" />
      </shape> 
</item>


</selector>
0
source
  <!-- When not clicked-->
  <item android:state_pressed="false"> <!-- you need to define ur state to false-->
    <shape >
    <gradient        
        android:angle="90"        
        android:centerColor="#ff008888"        
        android:endColor="@color/LightBlue"        
        android:startColor="@color/Lightgray"/>    
        <corners android:radius="12dip" />    
        <stroke        
            android:width="0dip"       
             android:color="@color/LightBlue" />
     </shape> 
  </item>
+3
source

( ur)

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- When clicked -->
    <item android:state_pressed="true"><shape>
            <gradient android:angle="90" 
                android:centerColor="#999966" 
                android:endColor="@android:color/white" 
                android:startColor="#5E5EFF" />

            <corners android:radius="12dip" />

            <stroke android:width="0dip"
                android:color="#5E5EFF" />
        </shape></item>
    <!-- When not clicked -->
    <item android:state_selected="false"><shape>
            <gradient android:angle="90" 
                android:centerColor="#ff008888" 
                android:endColor="#5E5EFF" 
                android:startColor="#999966" />

            <corners android:radius="12dip" />

            <stroke android:width="0dip" 
                android:color="#5E5EFF" />
        </shape></item>

</selector>
+1

: :

xml :

android:tag="0"

onClick :

String tag =  (String) v.getTag();
            if(!tag.equalsIgnoreCase("0"))
            {//apply which you want(styling)
                v.setBackgroundResource(R.drawable.active_baner_community);
                v.setTag("0");
            }
            else
            {//apply which you want(styling)
                v.setBackgroundResource(R.drawable.baner_community);
                v.setTag("1");
            }
0

...

, @drawable/selector_button

0

All Articles