Skip to content

UttamPanchasara/MultiTheme

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MultiTheme

Uplabs

Sample Project to demonstrate that how to use multi theme in Android application without using any Libraries.

It's very easy to implement multiple themes in your Application, with any customization that you wants, you can refer this project to implement/learn multiple theme in your Android Application.

Screenshot

Basic Steps to Implement Multiple Themes

Steps to implement multiple themes as Followed in this Sample Project :

Step 1:

Create custom attributes :

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="themes">
        <attr name="myWindowBackground" format="reference"/>
        <attr name="myTabBackgroundColor" format="reference"/>
        <attr name="myTabTextColor" format="reference"/>
        <attr name="myTabTextSelectedColor" format="reference"/>
        <attr name="myTabIndicatorColor" format="reference"/>
        <attr name="myPrimaryTextColor" format="reference"/>
        <attr name="mySecondaryTextColor" format="reference"/>
    </declare-styleable>
</resources>

Step 2:

Create custom theme style Based on your defined attributes :

<style xmlns:android="http://schemas.android.com/apk/res/android" name="Green">
        <item name="colorPrimary">@color/greenColorPrimary</item>
        <item name="colorPrimaryDark">@color/greenColorPrimaryDark</item>
        <item name="colorAccent">@color/greenColorAccent</item>

        <item name="myWindowBackground">@color/greenBackgroundColor</item>
        <item name="myTabBackgroundColor">@color/greenTabBackgroundColor</item>
        <item name="myTabTextColor">@color/greenTabTextColor</item>
        <item name="myTabTextSelectedColor">@color/greenTabTextSelectedColor</item>
        <item name="myTabIndicatorColor">@color/greenTabIndicatorColor</item>
        <item name="myPrimaryTextColor">@color/greenPrimaryText</item>
        <item name="mySecondaryTextColor">@color/greenSecondaryText</item>
 </style>

Step 3:

Set values with custom attributes :

 <android.support.design.widget.TabLayout
            app:layout_constraintTop_toBottomOf="@+id/toolbar"
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            app:tabBackground="?myTabBackgroundColor"
            app:tabTextColor="?myTabTextColor"
            app:tabIndicator="?myTabIndicatorColor"
            app:tabSelectedTextColor="?myTabTextSelectedColor"
            android:layout_height="wrap_content"/>

Apply Theme :

To Apply any theme use setTheme() just before super.onCreate :

override fun onCreate(savedInstanceState: Bundle?) {
        setTheme(R.style.Green)
        super.onCreate(savedInstanceState)
    }

Above steps help in setup multi theme styles and attributes

That's it!, To Switch theme at runtime refer this project.

Questions?

Ping-Me on : Twitter Facebook

profile for Uttam Panchasara at Stack Overflow, Q&A for professional and enthusiast programmers

Donate

If you found this project helpful or you learned something from the source code and want to thank me, consider buying me a cup of ☕

About

Sample Project to demonstrate that how to use multi theme in Android application without using any Libraries.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages