Git Product home page Git Product logo

multitheme's Introduction

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 โ˜•

multitheme's People

Contributors

uttampanchasara avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

zahidyameen

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.