Change default design theme to customized color

12,446

Solution 1

First Method:

In res/values-v21/styles.xml,

<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
    <item name="android:colorAccent">@color/custom_theme_color</item>
    <item name="android:colorPrimaryDark">@color/custom_theme_color</item>
    <item name="android:colorPrimary">@color/custom_theme_color</item>
</style>

First Method : Pink color

First Method: Green color

The above code is simple and working well. In Android studio, it could be able to change from default sky blue color to any other colors like pink or green!

Second Method:

Create 3 files under xml ie. res/xml such as checked.xml, unchecked.xml and custom_checkbox.xml

checked.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="2px" android:color="#FF00FF" />
<size android:height="20dp" android:width="20dp"/>
</shape>

unchecked.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="2px" android:color="#ffc0c0c0" />
<size android:height="20dp" android:width="20dp"/>
</shape>

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="@xml/checked" /> 
<item android:state_pressed="true"
      android:drawable="@xml/checked" /> 
<item android:drawable="@xml/unchecked" /> 
</selector>

From above second method, it (customized file) also could be able to create any shapes and colors based on our requirements. Even we can be able to customize the style, shapes and themes for a widget by using 2nd method.

Above two methods are working fine for me!

Solution 2

Also in from v23 with AppCompat you can use android.support.v7.widget.AppCompatCheckBox and change CheckBox style like this:

<android.support.v7.widget.AppCompatCheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:theme="@style/CheckBox"
    />

where in style.xml:

<style name="CheckBox" parent="Widget.AppCompat.CompoundButton.CheckBox">
    <item name="colorControlNormal">@color/checkbox_normal</item> <!-- border color -->
    <item name="colorControlActivated">@color/checkbox_activated</item> <!-- fill color -->
    <item name="colorControlHighlight">@color/checkbox_highlight</item> <!-- animation color -->
</style>
Share:
12,446
Achiever
Author by

Achiever

Updated on June 06, 2022

Comments

  • Achiever
    Achiever almost 2 years

    I am very new to Android Studio. As a beginner I have created a simple app just for testing purpose and to view the appearance of Android studio material theme. I am currently working with latest version ie. L preview - Studio 0.8.2 version.

    Here, I have just created textview, edittext, radio buttons and checkboxes. When I select male or female, it appears sky blue color. Could I be able to change sky blue color as a green or yellow color?

    I do not know what is the name for that. From the picture can able to see edittext, radio buttons and checkboxes selected state as a sky blue color. When I try to click or select anything then those checkboxes or radio buttons need to change from default color to other colors like green or yellow!

    Code

    In res/values/styles.xml,

    <resources>
    <!-- Base application theme. -->
    <color name="custom_theme_color">#b0b0ff</color>
    <style name="CustomTheme" parent="android:Theme.Material">
    <item name="android:colorBackground">@color/custom_theme_color</item>
    </style>
    </resources>
    

    In Android Studio Manifest.xml,

    android:theme="@style/CustomTheme" >
    

    Is there any other possible to change from default sky blue color to green or yellow or purple?

    Android Studio default color

    Is there any other way to change default sky blue color theme to other colors like pink or green?

    How could I do this?