私はいくつかの場所を検索しましたが、チェックボックスの枠線にはCheckBox
のドロアブルがありません。誰かが私を正しい方向に向けることができますか?ここでAndroid:CheckBoxの色を設定してください
はここ
(かろうじてボックスを見ることができます)、それは未チェックのように見えるものですチェック状態
ここでは、私が作るしようとしているものですですように見えます。
私はいくつかの場所を検索しましたが、チェックボックスの枠線にはCheckBox
のドロアブルがありません。誰かが私を正しい方向に向けることができますか?ここでAndroid:CheckBoxの色を設定してください
はここ
(かろうじてボックスを見ることができます)、それは未チェックのように見えるものですチェック状態
ここでは、私が作るしようとしているものですですように見えます。
あなたは、このためのカスタムチェックボックスのxmlファイルを使用することができます。それはcustom_checkbox.xml
drawables
フォルダ内の以下のXMLコードを保存し、名前:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"
android:drawable="@drawable/cbchk_blue"
android:state_focused="false">
</item>
<item android:state_checked="true"
android:drawable="@drawable/cbchk_blue"
android:state_focused="true">
</item>
<item android:state_checked="false"
android:drawable="@drawable/cbunchk_blue"
android:state_focused="false">
</item>
<item android:state_checked="false"
android:drawable="@drawable/cbunchk_blue"
android:state_focused="true">
</item>
</selector>
次に、このようなあなたのチェックボックスの背景として、このファイルを使用します。ここで私は私が使用私自身の画像をアップロードしています
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/custom_checkbox"
android:id="@+id/checkBox" />
をcbchk_blueとcbunchk_blueの代わり
これはドロウアブルで指定されています:android.R.drawable.checkbox_off_background
とandroid.R.drawable.checkbox_on_background
詳細をありがとうございます。私は、これらの2つのプロパティを責任あるものとして特定するのに問題があるようでした。ありがとうございました。 +1 – Kirk
その色を変更するにはどうすればいいですか? –
Activity HollowとWhite BackgroundのテーマHolo Darkを使用すると同じ問題が発生します。チェックボックスにはダークスタイルがあります。簡単な回避策は、直接Androidのホロ光から背景を設定されています
int id = Resources.getSystem().getIdentifier("btn_check_holo_light", "drawable", "android");
checkBox.setButtonDrawable(id);
あなたはこのすべてのものは、以下の答えでどのように機能するかを偉大な概要を見つけることができます:それは自由にすることが可能であるアンドロイド5とAPIレベル21ので https://stackoverflow.com/a/10139809/1170154
過去数時間私が探していたものとまったく同じです。ありがとう!! – jakeneff
これは私が探していたドロイドです。ありがとう!! – codinguser
これは私にとって完璧に機能しました!ありがとう! – wyzkid207
チェックボックスの色(および他の多くのウィジェット)を選択します。あなたはvalues/styles.xml
で、以前のAPIのフォールバックを持っていることを確認をしながら(自分のvalues-v21/styles.xml
に以下を追加します。
<style name="CustomCheckBox">
<item name="android:theme">@style/CheckBoxAppTheme</item>
</style>
<style name="CheckBoxAppTheme">
<item name="android:colorAccent">
@color/theFillColorInCheckedState
</item>
<item name="android:colorControlNormal">
@color/theBorderColorInUncheckedState
</item>
<item name="android:colorControlHighlight">
@color/theBackgroundColorWhenFocusingTheCheckBox
</item>
</style>
その後、あなたは自分のレイアウトであなたのチェックボックスにスタイルを適用する必要があります。
<CheckBox
style="@style/CustomCheckBox" />
だとあなたの好きな色でチェックボックスが表示されます!
大変申し訳ありませんが、これらの回答のほとんどが不完全であるか、マイナーなバグがあります。Androidのさまざまなバージョン間での「スタイリング」コントロールはepicお尻の痛み。デザインの制約が非常に厳しいプロジェクトで私の髪を引き出した後は、テストアプリを書いて、スタイリングスイッチやチェックボックス用のさまざまなソリューションを実際に試してテストしました。それはしばしばもう一方を持っています。ここに私が見つけたのは...
最初に:あなたは実際にそれらのいずれかをスタイルすることはできませんが、それらのすべてにテーマを適用することも、その1つだけを適用することもできます。
第2:あなたはXMLからすべてを行うことができ、2番目のvalues-v21/styles.xmlは必要ありません。
サード:それはあなたがAndroidの(私はあなたが確信しているように)の古いバージョンをサポートしたい場合は、2つの基本的な選択肢があり、スイッチに付属しています...
SwitchCompat
を使用することができますプラットフォーム間で同じように見えるようにすることができます。Switch
を使用することができます。テーマの残りの部分、または特定のスイッチだけをテーマにすることができます。古いバージョンのAndroidでは、スタイルのない旧式の四角形のスイッチが表示されます。ここでは単純な参照コードです。繰り返しますが、単純なHello Worldを作成した場合も同様です。このコードをドロップすると、あなたの心のコンテンツに遊ぶことができます。私はちょうど活動のためのXMLとスタイルを含めるつもりですので、すべてのことは...
activity_main.xml ...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.kunai.switchtest.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="'Styled' SwitchCompat" />
<android.support.v7.widget.SwitchCompat
android:id="@+id/switch_item"
android:layout_width="wrap_content"
android:layout_height="46dp"
android:layout_alignParentEnd="true"
android:layout_marginEnd="16dp"
android:checked="true"
android:longClickable="false"
android:textOff="OFF"
android:textOn="ON"
app:switchTextAppearance="@style/BrandedSwitch.text"
app:theme="@style/BrandedSwitch.control"
app:showText="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.kunai.switchtest.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Themed SwitchCompat" />
<android.support.v7.widget.SwitchCompat
android:id="@+id/switch_item2"
android:layout_width="wrap_content"
android:layout_height="46dp"
android:layout_alignParentEnd="true"
android:layout_marginEnd="16dp"
android:checked="true"
android:longClickable="false" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.kunai.switchtest.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Themed Switch" />
<Switch
android:id="@+id/switch_item3"
android:layout_width="wrap_content"
android:layout_height="46dp"
android:layout_alignParentEnd="true"
android:layout_marginEnd="16dp"
android:checked="true"
android:longClickable="false"
android:textOff="OFF"
android:textOn="ON"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.kunai.switchtest.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="'Styled' Switch" />
<Switch
android:id="@+id/switch_item4"
android:layout_width="wrap_content"
android:layout_height="46dp"
android:layout_alignParentEnd="true"
android:layout_marginEnd="16dp"
android:checked="true"
android:longClickable="false"
android:textOff="OFF"
android:textOn="ON"
android:theme="@style/BrandedSwitch"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.kunai.switchtest.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="'Styled' CheckBox" />
<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="46dp"
android:layout_alignParentEnd="true"
android:layout_marginEnd="16dp"
android:checked="true"
android:longClickable="false"
android:theme="@style/BrandedCheckBox"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.kunai.switchtest.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Themed CheckBox" />
<CheckBox
android:id="@+id/checkbox2"
android:layout_width="wrap_content"
android:layout_height="46dp"
android:layout_alignParentEnd="true"
android:layout_marginEnd="16dp"
android:checked="true"
android:longClickable="false"/>
</RelativeLayout>
ここではボイラープレートであります
のstyles.xml ...
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#3F51B5</item>
<item name="colorPrimaryDark">#303F9F</item>
<item name="colorAccent">#FF4081</item>
</style>
<style name="BrandedSwitch.control" parent="Theme.AppCompat.Light">
<!-- active thumb & track color (30% transparency) -->
<item name="colorControlActivated">#e6e600</item>
<item name="colorSwitchThumbNormal">#cc0000</item>
</style>
<style name="BrandedSwitch.text" parent="Theme.AppCompat.Light">
<item name="android:textColor">#ffa000</item>
<item name="android:textSize">9dp</item>
</style>
<style name="BrandedCheckBox" parent="AppTheme">
<item name="colorAccent">#aaf000</item>
<item name="colorControlNormal">#ff0000</item>
</style>
<style name="BrandedSwitch" parent="AppTheme">
<item name="colorAccent">#39ac39</item>
</style>
私は知っています、あなたはこれを構築するにはあまりにも怠惰です、あなたはただあなたのコードを書いてみたいです。わかった。
API_18:
これは完璧な答えです。私の人生を楽にしました。これは受け入れられるものでなければなりません。 – Rachit
はこれが最も効率的な方法となります。ここ
API_21 ...それはあなたがそれを実行したときのようになります。
アンドロイド:buttonTint = "黒@カラー/"
tks ...ソシンプル! – cesarsicas
あなたはこのAPI21 &
上記のアンドロイドのようなCHECKBOX色を設定することができます。
をbuttonTint = "@カラー/ YOUR_COLOR"
<CheckBox
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:buttonTint="@color/YOUR_COLOR" />
古いバージョンのサポート使用AppCompatCheckBox
V7ライブラリのアプリ:buttonTint = "@カラー/ YOUR_COLOR"
<android.support.v7.widget.AppCompatCheckBox
android:layout_height="wrap_content"
android:layout_width="match_parent"
app:buttonTint="@color/YOUR_COLOR" />
あなたはcheckBox.soの背景として画像を設定することができますが有する画像を撮ります国境とそれの背景を設定します。 – AkashG
'android:buttonTint =" @ color/mybrown "を設定すると、チェックボックスの色を簡単に変更できます。 – shauvik
android:buttonTint = "@ color/mybrown"は、チェックボックスの境界線の色を変更します。唯一の欠点は、それはあなたが望まない可能性のあるティックの色も変えることです。 – jetty