I've updated my project to use the latest appcompat support library, the new version uses material design checkboxes and radio buttons. My app is dark themed and the checkboxes are black which is hard to see. I'm trying to change their colors according to Maintaining Compatibility but so far nothing works.
res/values/styles.xml
<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
<!-- customize the color palette -->
<item name="colorAccent">@color/silver</item>
</style>
in build.gradle:
android {
compileSdkVersion 21
buildToolsVersion '21.1.1'
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
}
}
.....
.....
compile 'com.android.support:appcompat-v7:21.0.0'
AndroidManifest.xml:
<application
android:name="ee.mtakso.App"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppBaseTheme">
The checkboxes, editTexts, radiobuttons etc. remain black.
I don't know if this makes much difference, but the radiobuttons and checkboxes I'm using are for a CheckedTextView
, as following:
Single (radio button): android:checkMark="?android:attr/listChoiceIndicatorSingle"
Multi (check box): android:checkMark="?android:attr/listChoiceIndicatorMultiple"
Since these get the black colored material drawable, I don't think the issue is coming from them.
I had a similar problem with unchecked CheckBoxes and RadioButtons. I found the solution, when I figured out that controls takes their "Off" color from
<item name="android:textColorSecondary">@color/secondary_text</item>
EDIT:
Specifying, if your app's or activity's theme inherite one of L's AppCompat (Dark/Light/Light.DarkActionBar), you can set:
<style name="SampleTheme" parent="Theme.AppCompat">
<item name="colorAccent">@color/green</item>
<item name="android:textColorSecondary">@color/red</item>
</style>
And that's result:
Notice: When you get different effect you probably use "wrong" theme - make sure you set it correctly.
I believe this is an error in the AppCompat theme. My workaround adding two lines of code to each CheckBox in the xml layout file.
android:button="@drawable/abc_btn_check_material"
android:buttonTint="@color/colorAccent"
You never really want to direct reference abc_ drawables but in this case I found no other solution.
This applies to RadioButton widget as well! You would just use abc_btn_radio_material instead of abc_btn_check_material
I did this to change at least the border of a checkbox:
<style name="checkBoxComponent" parent="AppTheme">
//Checked color
<item name="colorAccent">@color/blueBackground</item>
//Checkbox border color
<item name="android:textColorSecondary">@color/grayBorder</item>
</style>
And in my layout
<android.support.v7.widget.AppCompatCheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="@style/checkBoxComponent"
android:text="Yay" />
Still figuring out how to get the background of the checkbox though. Hope it helps.
I had same problems as you. I looked once again at AppCompat v21 — Material Design for Pre-Lollipop Devices!
And I found this "All of your Activities must extend from ActionBarActivity, which extends from FragmentActivity from the v4 support library, so you can continue to use fragments.".
So I changed my activity to ActionBarActivity and it solved my problems. I hope it will solve yours too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With