2015-10-11 14 views
7

Android'deki engelli bir düğmenin rengini stiller veya başka biçimler yoluyla değiştirmek için bir yol var mı?Android'de devre dışı bırakılmış bir düğmenin rengini değiştirin

Şu anda şu var,

çekilebilir/button_default.xml

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

çekilebilir/button_default_shape.xml

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

    <solid android:color="@color/button_default_background"/> 
    <corners android:radius="3dp"/> 
</shape> 

değerler/styles.xml

<style name="AppTheme.Button"> 
    <item name="android:background">@drawable/button_default</item> 
    <item name="android:textColor">@android:color/white</item> 
    <item name="android:textAllCaps">false</item> 
    <item name="android:paddingTop">10dp</item> 
    <item name="android:paddingBottom">10dp</item> 
    <item name="android:focusable">true</item> 
    <item name="android:clickable">true</item> 
    <item name="android:gravity">center</item> 
    <item name="android:textStyle">bold</item> 
    <item name="android:textSize">17sp</item> 
    <item name="android:textAppearance">@style/CustomFontAppearance</item> 
</style> 

cevap

13

Bu eyaletlerde farklı çekilebilir öğeler için bir seçici kullanmanız gerekir.

Böyle bir seçici oluşturabilirsiniz:

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:drawable="@drawable/your_enabled_drawable" android:state_enabled="true" /> 
    <item android:drawable="@drawable/your_disabled_drawable" android:state_enabled="false" /> 
    <!-- default state--> 
    <item android:drawable="@drawable/your_enabled_drawable" /> 
</selector> 
1

deneyin bu -

çekilebilir/bg_button.xml: - Düğmenizi bu sadece set arka sonra

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

    <item android:drawable="@drawable/bg_button_focused" android:state_selected="true"/> 
    <item android:drawable="@drawable/bg_button_pressed" android:state_pressed="true"/> 
    <item android:drawable="@drawable/bg_button_disabled" android:state_enabled="false" /> 
    <item android:drawable="@drawable/bg_button_normal"/> 

</selector> 

bunun gibi -

<Button 
    android:id="@+id/button" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/bg_button" 
    android:text="Button"/> 
3

android için seçicideki rengini belirtin: çekilebilir

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_enabled="false"> 
     <shape> 
      <solid android:color="#32ff09" /> 
     </shape> 
    </item> 
</selector> 

olarak = "false" state_enabled Ve düğmesinin arka planına bu çekilebilir kaynağı uygulamak

<Button 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/drawble_name" 
    android:enabled="false" 
    android:text="Selector Applied Button" /> 
İlgili konular