2015-10-11 11 views
7

スタイルやその他のフォームを通じてアンドロイドの無効なボタンの色を変更する方法はありますか?アンドロイドの無効なボタンの色を変更する

私は現在、以下、

描画可能/ 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> 

描画可能/ 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> 

値/の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> 

答えて

13

これらの状態では、さまざまなドロワーブルにセレクタを使用する必要があります。

あなたはこのようなセレクタを作成することができます

<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

を試してみて、この -

描画可能/ bg_button.xml: - あなたのボタンでこのセットだけな背景の後

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

このように -

<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用セレクタで色を指定:描画可能

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

として= "false" をstate_enabled、ボタンの背景には、この描画可能リソースを適用

<Button 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/drawble_name" 
    android:enabled="false" 
    android:text="Selector Applied Button" /> 
関連する問題