Question

i have made a style for the button to be seen in a "bolding" way. but when i use the setEnabled(false) and setClickable(false) it make the button disabled but i can't see it because i am using a style , so how can i make the button more like "into" (as if it is clicked) when i use set Enable(false) ???

code:

signin.setClickable(false);
signin.setEnabled(false);

I don't want to discard the style but to modify it but i don't know how.

style:

 <style name="btnStyleShakespeare" parent="@android:style/Widget.Button">
   <item name="android:textSize">15sp</item>
   <item name="android:textStyle">bold</item>
   <item name="android:textColor">#FFFFFF</item>
   <item name="android:gravity">center</item>
   <item name="android:shadowColor">#000000</item>
   <item name="android:shadowDx">1</item>
   <item name="android:shadowDy">1</item>
   <item name="android:shadowRadius">0.6</item>
   <item name="android:background">@drawable/custom_btn_shakespeare</item>
   <item name="android:padding">10dip</item>

thanks for any help.

Was it helpful?

Solution 2

Create another XML file in res\color named something like text_color.xml (based on Adil Soomro's answer here):

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <!-- disabled state -->
  <item android:state_enabled="false" android:color="#000000" /> 
  <item android:color="#FFFFFF"/>
</selector>

In your style.xml, replace

<item name="android:textColor">#FFFFFF</item>

to

<item name="android:textColor">@color/text_color</item>
 

OTHER TIPS

You need to use a custom selector list which will be set as your button background.
Something like: btnSelector.xml in your /drawable

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- when button is pressed (touched/clicked) -->
    <item android:drawable="@drawable/button_selected" android:state_selected="true" />
    <!-- When button is disabled, i.e clickable and enabled is set to false -->
    <item android:drawable="@drawable/button_disabled" android:state_enabled="false"/>  
      <!-- Default, when button is clickable -->
    <item android:drawable="@drawable/button_normal" android:state_enabled="true" />
</selector>  

And you will have 3 different drawables each for clicked/pressed state, disabled state and normal state.
Then in your custom style change:

@drawable/btnSelector.xml

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top