2017-05-02 10 views
0

スイッチをオン/オフの両方の状態で同様に見せたいと思う。ラウンドサムと同じ背景色の同じ色。誰もする方法を知っていますか?スイッチをオン/オフの両方の状態で似たようにする

EDIT:

Switch chooser = (Switch) dialog.findViewById(R.id.dswitch); 

    ColorStateList buttonStates = new ColorStateList(
      new int[][]{ 
        new int[]{android.R.attr.state_checked}, 
        new int[]{-android.R.attr.state_enabled}, 
        new int[]{} 
      }, 
      new int[]{ 
        Color.RED, 
        Color.RED, 
        Color.GREEN 
      } 
    ); 
    chooser.setButtonTintList(buttonStates); 

ところで、私のスイッチは、カスタム警告ダイアログです。

答えて

0

、この方法を試してみてください:

<style name="Color1SwitchStyle"> 
     <item name="colorControlActivated">#491010</item> 
     <item name="colorSwitchThumbNormal">#491010</item> 
    </style> 

変更を:スイッチ

<android.support.v7.widget.SwitchCompat 
     android:layout_width="match_parent" 
     android:id="@+id/switchInput" 
     android:theme="@style/ColorSwitchStyle" 
     android:layout_height="wrap_content" /> 

そして、あなたのstyles.xmlファイルで、この特定のスイッチのスタイルを持っているの代わりに

まず使用SwitchCompatあなたの要件に応じて色の値とあなたは良いです。

----------------------- ****** ----------------- ----------------------

あなたのスイッチのためにこれを試すことができます。

ColorStateList buttonStates = new ColorStateList(
     new int[][]{ 
       new int[]{android.R.attr.state_checked}, 
       new int[]{-android.R.attr.state_enabled}, 
       new int[]{} 
     }, 
     new int[]{ 
       Color.RED, 
       Color.BLUE, 
       Color.GREEN 
     } 
); 
switchInput.setButtonTintList(buttonStates); 

あなたがstate_checkedとstate_enabledの色を変更することができます同じ色です

+0

動作しません。私はデフォルトの色を取得します。 – Lcukerd

+0

私の編集をチェックしてください。これが私のやり方です。 – Lcukerd

+0

ありがとうございました。 styles.xmlでこれらのタグをどこで使うのか教えていただけますか? – Lcukerd

関連する問題