Theme/Style all checkboxes
Unfortunately, colorControlNormal
and colorControlActivated
are theme attributes, not style attributes, so they only work if they're defined in the view's theme. There is no way that I know of to set a "default theme" for all views of a certain type; attributes like checkboxStyle
can only set a default style for all checkboxes. Additionally, you can't "trick" the system by writing something like:
<style name="MyTheme" parent="Theme.AppCompat">
...
<item name="checkboxStyle">@style/MyCheckBoxStyle</item>
...
</style>
<style name="MyCheckBoxStyle" parent="Base.Widget.AppCompat.CompoundButton.CheckBox">
<item name="android:theme">@style/MyCheckboxTheme</item>
</style>
<style name="MyCheckboxTheme">
<item name="colorControlNormal">#8AFFFFFF</item>
<item name="colorControlActivated">@android:color/white</item>
</style>
Your choices are:
- Modify
colorControlNormal
andcolorControlActivated
in your app's theme - Modify
colorControlNormal
andcolorControlActivated
in your activity's theme - Manually set the
android:theme
attribute to every checkbox you want to change (or to the parent viewgroup holding these checkboxes)
Edit: potential workaround
Depending on your exact requirements, you might be able to get away with this:
<style name="MyTheme" parent="Theme.AppCompat">
<item name="checkboxStyle">@style/MyCheckboxStyle</item>
</style>
<style name="MyCheckboxStyle" parent="Widget.AppCompat.CompoundButton.CheckBox">
<item name="buttonTint">#8AFFFFFF</item>
</style>
This will change the color of every checkbox in your app without requiring the use of theme attributes. You can even use a color selector resource for buttonTint
if you want different colors for checked/unchecked:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@android:color/white" android:state_checked="true"/>
<item android:color="#8AFFFFFF"/>
</selector>
Android replace checkbox style with custom drawable selector
Use below line of code, i think it will work
yourcheckbox.setButtonDrawable(yourdrawable);
Change style of checked checkbox in Option menu item
As per your code snippets and screenshot . I will suggest to change your acentColor
ColorAccent will be display in your checkBox selected value in those you have given in accentColor in your style.
I hope it will work.
android checkbox style not working on ICS
It seems I needed to add the following lines to styles.xml
<item name="checkboxStyle">@style/CheckBoxStyle</item>
<item name="radioButtonStyle">@style/RadioButtonStyle</item>
to compliment the lines that were already there...
<item name="android:radioButtonStyle">@style/RadioButtonStyle</item>
<item name="android:checkboxStyle">@style/CheckBoxStyle</item>
!
How to change the color of the tick in a Material Design Checkbox?
You should use custom icon for your CheckBox
. It should be a selector
drawable like this
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false"
android:drawable="@drawable/button_normal" /> <!-- unchecked -->
<item android:state_checked="true"
android:drawable="@drawable/button_checked" /> <!-- checked -->
<item android:drawable="@drawable/button_normal" /> <!-- default -->
</selector>
Drawables button_checked
and button_normal
should be defined by you.
Then use this drawable like this
<com.google.android.material.checkbox.MaterialCheckBox
android:theme="@style/CheckBoxTheme"
android:button="@drawable/checkbox_selector"
/>
More info here and here
Hope it helps.
How to create the checkBox in circular shape?
After spending some time, i have created this template, which you can use. You may need to modify as required.
In activity.xml
<CheckBox
android:id="@+id/checkb"
android:layout_width="115dp"
android:layout_height="50dp"
android:button="@drawable/custom_checkbox"
android:scaleX="3"
android:scaleY="3"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="15dp"
android:layout_marginEnd="15dp" />
create a new xml in drawable folder called custom_checkbox.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/checked" />
<item android:state_pressed="true"
android:drawable="@drawable/checked" />
<item android:state_pressed="false"
android:drawable="@drawable/unchecked" />
</selector>
create a new xml in drawable folder called checked.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<layer-list>
<item>
<shape android:shape="oval">
<corners android:radius="1dp" />
<stroke
android:width="1dp"
android:color="#777" />
<gradient
android:startColor="#990000"
android:centerColor="#990000"
android:endColor="#990000"
android:angle="270" />
<size
android:width="30dp"
android:height="30dp" />
</shape>
</item>
<item
android:width="8dp"
android:height="2dp"
android:top="20dp"
android:left="6dp">
<rotate
android:fromDegrees="45">
<shape android:shape="rectangle">
<solid android:color="#fff"/>
</shape>
</rotate>
</item>
<item
android:width="19dp"
android:height="2dp"
android:top="16dp"
android:left="9dp">
<rotate
android:fromDegrees="-45">
<shape android:shape="rectangle">
<solid android:color="#fff"/>
</shape>
</rotate>
</item>
</layer-list>
</item>
</selector>
create a new xml in drawable folder called unchecked.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<corners android:radius="1dp" />
<stroke
android:width="1dp"
android:color="#777" />
<gradient
android:startColor="#990000"
android:centerColor="#990000"
android:endColor="#990000"
android:angle="270" />
<size
android:width="30dp"
android:height="30dp" />
</shape>
When unchecked it looks as below. (you can add the code between from checked.xml and modify the top and left to give X when checkbox is not checked)
When checked it will look as below
If this works mark it as answer.
Related Topics
Rendering Problems in Android Studio V 1.1/1.2
How to Get Chrome Browsing History/Bookmarks in Our Android App
How to Force an Intentservice to Stop Immediately with a Cancel Button from an Activity
Error: Mapfragment Cannot Be Cast to Android.Support.V4.App.Fragment
Firebase: How to Set Default Notification Channel in Android App
Android - How to Intercept the 'Install Application' Intent
Android Sdk Tools Revision 22 Issue
Difference Between Addvalueeventlistener() and Addlistenerforsinglevalueevent() of Firebase
Setting Android Theme Background Color
Change Date String Format in Android
How Might I Add a Watermark Effect to an Image in Android
Using an Android Library Project Activity Within Another Project
How to Have 1 Firebase Database for 2 Apps with Different Package Names
Cannot Create an Instance of Class Viewmodel
Android Repeat Action on Pressing and Holding a Button