
You need to test the ratio irrespective of the color of the text in this case. Kotlin package .theme import .graphics. If you choose to have a background with your primary color, then you only need to test for the 15.8:1 contrast ratio. This way you can build your color picker. Step 3: Adding a new color to the Color.kt file Navigate to app > java > your app’s package name > ui.theme > Color.kt file and add the below code to it. You can assign this drawable to your checkbox as follow: Or you can set the colors (blue, red, etc.) as background color to your checkbox and create only one state drawable file and reuse it for all based on your requirements.


You can create this type of state drawable file for each color (this will allow to render different color checkbox based on requirement/color).
#ANDROID COLOR UI PICKER ANDROID#
The above drawable will show check_mark_image for checked state and transparent for unchecked state. Starting from Android S, the framework provides the ability to support dynamic colors in your UI based on the users wallpaper or color choice on the device. For this use case, we can use StateDrawable, which can change it's UI based on the state (selected/unselected).įollowing is an example of StateDrawable for checkbox/radio button:įile location: app/resources/drawables/color_picker_item.xml Now, checkbox/radio buttons can take care of selection part, now we would need to make the UI updates based on whether the color is selected or not. In case you need select mutiple colors at a time, then use Checkbox. Since the Radio buttons have inbuild mechanism of selecting only one element at a time.

First thing first, you would need to use RadioButton for this use case.
