Android appcompat-v7 checkbox icons: 21.0.0

I updated my project to use the latest application support library, the new version uses flags for creating materials and radio buttons. My application is dark and the flags are black, which is hard to see. I am trying to change their colors to maintain compatibility , but so far nothing has worked.

RES / value / 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"> 

Flags, editTexts, radioobuttons, etc. stay black.

Edit

I don't know if this matters a lot, but I use radio buttons and check boxes for CheckedTextView , as shown below:

Single (switch): android:checkMark="?android:attr/listChoiceIndicatorSingle"

Multi (checkbox): android:checkMark="?android:attr/listChoiceIndicatorMultiple"

Since they get the material available in black, I don’t think the problem comes from them.

+57
android material-design
Nov 10 '14 at 11:44
source share
18 answers

I had a similar problem with the unverified CheckBoxes and RadioButtons . I found a solution when I realized that the controls take their “Disconnected” color from

<item name="android:textColorSecondary">@color/secondary_text</item>




EDIT:

The task, if your application or action theme inherits one of the L 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 this result:

enter image description here

Note: When you get a different effect, you are probably using the “wrong” theme - make sure you install it correctly.

+116
Nov 10 '14 at 18:42
source share

I believe this is a bug in the AppCompat theme. My workaround is 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 want to send abc_ drawables links, but in this case I did not find another solution.

This also applies to the RadioButton widget! You would just use abc_btn_radio_material instead of abc_btn_check_material

+34
Jan 16 '15 at 16:05
source share

I had the same problems as you. I looked again at AppCompat v21 - Material Design for Preloaded Lollipop Devices!

And I found this: "All your actions should extend from the ActionBarActivity , which extends from the FragmentActivity from the v4 support library, so you can continue to use fragments."

So, I changed my activity to ActionBarActivity and solved my problems. I hope this solves your problem too.

+14
Nov 15 '14 at 16:42
source share

I was looking for a solution, and I found it.

Step 1
ActionBarActivity Extension

 public static class MyActivity extends ActionBarActivity { //... } 

Step 2
Two values ​​are written in your style file

 <style name="MyTheme" parent="Theme.AppCompat.NoActionBar"> <item name="colorAccent">#009688</item> <item name="android:textColorSecondary">#757575</item> </style> 

colorAccent - checked color
android: textColorSecondary - unverified color

Step 3
Set your theme in AndroidManifest.xml

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.test.radiobutton" android:versionCode="1" android:versionName="1.0"> <application android:label="@string/app_name" android:icon="@drawable/ic_launcher"> .... <activity android:name=".activity.MyActivity " android:theme="@style/MyTheme"/> ..... </application> </manifest> 



RESULT
Android 5
android_5
Android 4.2.2
android_4.2.2

+9
Feb 17 '15 at 7:42
source share

1. Declare a custom style in the styles.xml file.

 <style name="CustomStyledRadioButton" parent="Theme.AppCompat.Light"> <item name="colorControlNormal">@color/red</item> <item name="colorControlActivated">@color/red_pressed</item> </style> 

2. Apply this style to your RadioButton via the android: theme attribute.

  <RadioButton android:id="@+id/rb_option1" android:layout_width="match_parent" android:layout_height="wrap_content" android:checked="true" android:gravity="left" android:lineSpacingExtra="10dp" android:padding="10dp" android:text="Option1" android:textColor="@color/black" android:theme="@style/CustomStyledRadioButton"/> 
+7
Jan 27 '16 at 12:58
source share

I did this to change at least the border of the 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. Hope this helps.

+7
Apr 27 '16 at 20:43
source share

To specify colors, override:

for marked color:

 <item name="android:colorControlActivated">@color/your_color</item> 

for non-screen color:

 <item name="android:colorControlNormal">@color/your_color</item> 
+4
Apr 13 '16 at 8:27
source share

You will have many problems with the compatibility library with both checkboxes and radio buttons.

1) They come only in black for any Android 4.x devices. They work on Android 5.x and 2.x (don't ask me why this works on 2.x, they have no idea).

2) They don’t have a disabled state (it doesn’t matter if all of your checkboxes are turned on, otherwise you may surprise very badly).

Note that the default background for the dark theme is gray, not black, so if you keep it ok by default.

To solve this problem, I created a white and disabled version of the following drawings, all added to my main project, but not in the compatibility project (for the obvious purpose of maintenance):

 abc_btn_check_to_on_mtrl_000 abc_btn_check_to_on_mtrl_015 abc_btn_radio_to_on_mtrl_000 abc_btn_radio_to_on_mtrl_015 

Then are created accessible for managing all states (to override the initial state):

For example, a dark theme will use this:

 <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_enabled="false" android:state_checked="true" android:drawable="@drawable/abc_btn_check_to_on_mtrl_015_disabled" /> <item android:state_enabled="true" android:state_checked="true" android:drawable="@drawable/abc_btn_check_to_on_mtrl_015" /> <item android:state_enabled="true" android:drawable="@drawable/abc_btn_check_to_on_mtrl_000" /> <item android:drawable="@drawable/abc_btn_check_to_on_mtrl_000_disabled" /> </selector> 

The light theme will use this (user can switch the theme in my application):

 <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_enabled="false" android:state_checked="true" android:drawable="@drawable/abc_btn_check_to_on_mtrl_015_disabled" /> <item android:state_enabled="true" android:state_checked="true" android:drawable="@drawable/abc_btn_check_to_on_mtrl_015_light" /> <item android:state_enabled="true" android:drawable="@drawable/abc_btn_check_to_on_mtrl_000_light" /> <item android:drawable="@drawable/abc_btn_check_to_on_mtrl_000_disabled" /> </selector> 

Then all I had to do was redefine the default compatibility theme (both activity and dialogue, for dark / dark themes), adding something like this:

  <item name="android:listChoiceIndicatorSingle">@drawable/abc_btn_radio_material</item> <item name="android:listChoiceIndicatorMultiple">@drawable/abc_btn_check_material</item> 

And this is for light topics:

  <item name="android:listChoiceIndicatorSingle">@drawable/abc_btn_radio_material_light</item> <item name="android:listChoiceIndicatorMultiple">@drawable/abc_btn_check_material_light</item> 

Now I have full functional flags and radio on all versions of Android! IMO in the compatible library was not tested at all for a dark theme, only a white theme was used. A disconnected state will probably never be used by dev of the compat lib.

+3
Nov 28 '14 at 9:37
source share

100% Work

Just create a style for your RadioButton and change the colorAccent as shown below:

 <style name="RadioButtonTeal" parent="Theme.AppCompat.Light.NoActionBar"> <item name="colorAccent">@color/md_teal_600</item> </style> 

Then just add this style to your AppCompatRadioButton:

 <android.support.v7.widget.AppCompatRadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:theme="@style/RadioButtonTeal" /> 
+3
Jan 27 '16 at 17:39
source share

Just stretch your ActionBarActivity like this:

 Public class MainActivity extends ActionBarActivity { //... } 
+2
Dec 16 '14 at 19:53
source share

What you did should work as per the Android blog post:

colorAcent : a striking addition to the color of the main brand. By default, this color applies to wireframe controls (through colorControlActivated).

colorControlActivated . Color is applied to wireframe controls in their activated (e.g., verified) state.

Perhaps the problem is related to your theme, which has @ style / Theme.AppCompat.Light as the parent, just try Theme.AppCompat:

 <style name="AppBaseTheme" parent="Theme.AppCompat.Light"> <!-- customize the color palette --> <item name="colorAccent">@color/silver</item> </style> 
+1
Nov 10 '14 at 16:03
source share

If you want to change a specific flag background color (not the whole application), you can try this trick:

Create a custom_checkbox.xml file for the background in the drop-down folder:

  <shape xmlns:android="http://schemas.android.com/apk/res/android"> <stroke android:width="14dp" android:color="@android:color/transparent" /> <solid android:color="#ffffff" /> //the intended color of the background <corners android:radius="2dp" /> </shape> 

and then set it as the background of the checkbox:

 <CheckBox android:id="@+id/rebate_tnc_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/custom_checkbox" /> 
+1
Jan 04 '16 at 3:31 on
source share

you can pass another topic to the warning dialog box design

 <style name="RadioButton" parent="Theme.AppCompat.Light.Dialog.Alert"> <item name="colorControlNormal">@color/red</item> <item name="colorControlActivated">@color/green</item> </style> 

and use this style in the constructor

 new AlertDialog.Builder(getContext(), R.style.RadioButton); 
+1
Aug 26 '16 at 12:03
source share

Parent of your AppTheme @style/Theme.AppCompat.Light .

Change it to @style/Theme.AppCompat .

Now your controls will be bright against a dark background.

0
Jan 11 '15 at 17:08
source share

I am using the appcompat v21 library:

 <style name="AppBaseTheme" parent="Theme.AppCompat.Light"> <item name="colorPrimary">@color/custom_color</item> <item name="colorAccent">@color/custom_color</item> </style> 

This style makes my flag appear with a material design (tested on Android 5, 4.3, 4.1.1), but on Android 2.3.3 it appears with the old flag style.

0
Jan 12 '15 at 14:25
source share

If you try to create a ComboBox manually (the new ComboBox () ...), then no matter what you set, they will always be black. It’s clear that the compatibility library is broken, for this I created an error report: https://code.google.com/p/android/issues/detail?id=158020

0
Mar 02 '15 at 21:19
source share

add this syntax to color the widget, such as a check box or android switch: buttonTint = "@ color / silver"

0
Jul 01 '15 at 11:05
source share

Add

 <item name="android:textColorSecondary">@color/secondary_text</item> 

in style.xml and style.xml (v21)

0
Aug 01 '15 at 1:19
source share



All Articles