The theme of is customizer of any any program or apps. it’s change looks colour design imageview and much more. in short it’s contain different UI options in one program.

Logic in theming

There are not any preset logic it’s contain the different types of logic. like in onclick change imageview,or change colour of any view or background. for example if i create a application and i want to add Dark and light mode theme.

I create a linear and a switch for enable and disable dark and light mode in apps

Code

<LinearLayout
xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
xmlns:app=”http://schemas.android.com/apk/res-auto&#8221;
xmlns:tools=”http://schemas.android.com/tools&#8221;
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical”>
<Switch
android:id=”@+id/switch1″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:padding=”8dp”
android:text=”Switch”
android:textSize=”12sp”
android:textColor=”#000000″/>
<LinearLayout
android:id=”@+id/linear1″
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:padding=”8dp”
android:background=”#000000″
android:orientation=”horizontal”/>
</LinearLayout>

After that in onclick listener i use control block if else and set action if switch checked set background color white else background color black.

Code

if (switch1.isChecked()) {
linear1.setBackgroundColor(0xFFFFFFFF);
}
else {
linear1.setBackgroundColor(0xFF000000);

In this condition default colour of my application is black and if i want enable white mode need to click switch.

Note

Remember that i used a simple example for understanding theming. it’s back default settings automatically if close the application.

I used a switch to change theme but they not only one logic to create theme features. you can add your own logic like use variable number to set color and set condition if contain operator or if variable equal to any number value than apply condition to set or change color.