<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Priyanka More on Medium]]></title>
        <description><![CDATA[Stories by Priyanka More on Medium]]></description>
        <link>https://medium.com/@morepriyanka1794?source=rss-374f26f06c1a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*hUA26b51-bHRoa0d.</url>
            <title>Stories by Priyanka More on Medium</title>
            <link>https://medium.com/@morepriyanka1794?source=rss-374f26f06c1a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 04:28:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@morepriyanka1794/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Firebase Authentication & Email Verification In Android]]></title>
            <link>https://morepriyanka1794.medium.com/firebase-authentication-email-verification-in-android-f1cf19efd824?source=rss-374f26f06c1a------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1cf19efd824</guid>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[emailverifier]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[firebaseauthentication]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Priyanka More]]></dc:creator>
            <pubDate>Mon, 21 Jun 2021 10:00:22 GMT</pubDate>
            <atom:updated>2021-06-21T10:00:22.280Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DUgBPN9cVfOLG_UR" /></figure><p><strong>What is firebase:</strong></p><p>Firebase is a collection of tools and a complete solution for backend, it handles Authentication, real time database, cloud firestore, etc and many more features.</p><p>Here in short we will see what tools are present in the firebase.</p><ul><li><strong>Build: </strong>Authentication, Cloud firestore, Realtime Database, Storage, Hosting, Functions, machine learning.</li><li><strong>Release &amp; Monitoring:</strong> Crashlytics, Performance, Test lab, App Distribution.</li><li><strong>Analytics: </strong>Dashboard, Real time, Events, Conversions,Audiences, Funnels, Custom defincations, Latest release, Retention, DebugView<strong>.</strong></li><li><strong>Engage:</strong> Predictions, A/B testing, Cloud messaging, In-App messaging, Remote config, Dynamic Links, AdMob,</li><li><strong>Extensions</strong></li></ul><p>This is a short introduction to firebase.</p><p>Here in this blog we will see how to implement <strong>Firebase Authentication</strong> <strong>&amp; Verification</strong> of a user using an email address.</p><p><strong>Step 1:</strong></p><p>Step is we need to create new project in android studio, in AndroidStudio Go to <strong>File</strong> -&gt; <strong>New</strong> -&gt; <strong>New Projec</strong>t -&gt; <strong>Choose activity</strong> ( I am selecting empty activity you can choose as per your choice ) -&gt;<strong> Give name to project and choose directory</strong> ( where we want to save project and ) -&gt; <strong>Click on finish</strong>.</p><p><strong>Step 2:</strong></p><p>Create a project on <a href="https://console.firebase.google.com/">Firebase console</a>.</p><p>To register project on firebase follow the steps:</p><ol><li>Click on add project, after clicking you will redirect to create project tab.</li><li>On the create project tab give the project name, and click on the continue button.</li><li>Follow the steps and click on create project.</li></ol><p>Here we are done with the project creation on firebase.</p><p>Now we need to add an application, here we will see how to add an android application to firebase project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KYOE50AoHErwj83M" /></figure><p>In our created firebase project we will see symbols of iOS, Android, Web. So we will see how to register Android applications.</p><p>On clicking on the Android symbol, we will redirect to <strong>“Add Firebase to your Android app” </strong>screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*l697bNnB1aBtyMsw" /></figure><p>Need to follow 4 steps for registration of application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/0*tkzO7A4EzV7EjmrZ" /></figure><p>Register app</p><ol><li>Add package name of android studio application.</li><li>Add the nickname of the application.</li><li>Add Debug signing certificate SHA-1.</li><li>Click on the Register app.</li></ol><p>Download Config file</p><ol><li>Download the google-services.json file</li><li>Add into the app folder of the android studio project.</li></ol><p>Add firebase SDK into Android Studio project</p><ol><li>Project-level build.gradle</li></ol><p><em>buildscript {</em></p><p><em>repositories {</em></p><p><em>// Check that you have the following line (if not, add it):</em></p><p><em>google() // Google’s Maven repository</em></p><p><em>}</em></p><p><em>dependencies {</em></p><p><em>// Add this line</em></p><p><em>classpath ‘com.google.gms:google-services:4.3.8’</em></p><p><em>}</em></p><p><em>}</em></p><p><em>allprojects {</em></p><p><em>repositories {</em></p><p><em>// Check that you have the following line (if not, add it):</em></p><p><em>google() // Google’s Maven repository</em></p><p><em>…</em></p><p><em>}</em></p><p><em>}</em></p><p>2App-level build.gradle</p><p><em>apply plugin: ‘com.android.application’</em></p><p><em>// Add this line</em></p><p><em>apply plugin: ‘com.google.gms.google-services’</em></p><p><em>dependencies {</em></p><p><em>// Import the Firebase BoM</em></p><p><em>implementation platform(‘com.google.firebase:firebase-bom:28.0.1’)</em></p><p><em>// Add the dependency for the Firebase SDK for Google Analytics</em></p><p><em>// When using the BoM, don’t specify versions in Firebase dependencies</em></p><p><em>implementation ‘com.google.firebase:firebase-analytics’</em></p><p><em>// Add the dependencies for any other desired Firebase products</em></p><p><em>// </em><a href="https://firebase.google.com/docs/android/setup#available-libraries"><em>https://firebase.google.com/docs/android/setup#available-libraries</em></a></p><p><em>}</em></p><ol><li>Click on Continue to console</li></ol><p>Here we are done with the registration process.</p><p>Now we have to enable the authentication function in the firebase project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-AbRqnCQiuumDwi4" /></figure><p>After clicking on the enable button in the sign-in-method option choose the method which you want to use for Authentication. Here we are going to see how to Authenticate users using email addresses.</p><p>So here I am enabling the email/password option for Authentication.</p><p>We can enable more than one authentication method as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3VW8oKrbA-jbKLe_" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DvKc7FxcZHdmP2Wd" /></figure><p>So here we are done with our firebase settings.</p><p>Lets see the coding section…….</p><p><strong>Step 3:</strong></p><p>Create instance of FirebaseAuth:</p><p><em>public static final FirebaseAuth AUTH = FirebaseAuth.getInstance();</em></p><p>Create User using email and password:</p><p><strong><em>protected</em></strong><em> </em><strong><em>final</em></strong><em> </em><strong><em>void</em></strong><em> createUserAuthWithEmailAndPassword(String emailId, String password) {</em></p><p><em>AUTH.createUserWithEmailAndPassword(emailId, password).addOnCompleteListener((@NonNull Task&lt;AuthResult&gt; task) -&gt; {</em></p><p><strong><em>if</em></strong><em> (task.isSuccessful())</em></p><p><em>Toast.makeText(getApplicationContext(),”Success”,Toast.LENGHT_LONG).show();</em></p><p><strong><em>else</em></strong><em> Toast.makeText(getApplicationContext(),task.getException()).getMessage(),Toast.LENGHT_LONG).show();</em></p><p><em>});</em></p><p><em>}</em></p><p>Sign in with Email and Password:</p><p><strong>protected</strong> <strong>final</strong> <strong>void</strong> authSignInWithEmailAndPassword(String emailId, String password) {</p><p>AUTH.signInWithEmailAndPassword(emailId, password).addOnCompleteListener((@NonNull Task&lt;AuthResult&gt; task) -&gt; {</p><p><strong>if</strong> (task.isSuccessful())</p><p>Toast.makeText(getApplicationContext(),”Success”,Toast.LENGHT_LONG).show();</p><p><strong>else</strong></p><p>Toast.makeText(getApplicationContext(),task.getException()).getMessage(),Toast.LENGHT_LONG).show();</p><p>});</p><p>}</p><p>Send verification email to registered user:</p><p>To send verification email to registered users we need to get a FirebaseUser instance.</p><p><em>public static final FirebaseUser AUTH_USER = FirebaseAuth.getInstance().getCurrentUser()!=null ? FirebaseAuth.getInstance().getCurrentUser(): null ;</em></p><p>Send verification email using below method:</p><p><strong><em>protected</em></strong><em> </em><strong><em>final</em></strong><em> </em><strong><em>void</em></strong><em> verifyEmailIdSentEmail( FirebaseUser firebaseUser){</em></p><p><em>firebaseUser.sendEmailVerification()</em></p><p><em>.addOnCompleteListener(</em><strong><em>new</em></strong><em> OnCompleteListener&lt;Void&gt;() {</em></p><p><em>@Override</em></p><p><strong><em>public</em></strong><em> </em><strong><em>void</em></strong><em> onComplete(@NonNull Task&lt;Void&gt; task) {</em></p><p><strong><em>if</em></strong><em> (task.isSuccessful()) {</em></p><p>Toast.makeText(getApplicationContext(),”Success”,Toast.LENGHT_LONG).show();</p><p><em>}</em></p><p><strong><em>else</em></strong></p><p><em>{ </em>Toast.makeText(getApplicationContext(),”Failed”,Toast.LENGHT_LONG).show();</p><p><em>}</em></p><p><em>}</em></p><p><em>}).addOnCanceledListener(</em><strong><em>new</em></strong><em> OnCanceledListener() {</em></p><p><em>@Override</em></p><p><strong><em>public</em></strong><em> </em><strong><em>void</em></strong><em> onCanceled() {</em></p><p>Toast.makeText(getApplicationContext(),task.getException()).getMessage(),Toast.LENGHT_LONG).show();</p><p><em>}</em></p><p><em>});</em></p><p><em>}</em></p><p>We can check is user is verified or not:</p><p><strong><em>public</em></strong><em> </em><strong><em>static</em></strong><em> </em><strong><em>boolean</em></strong><em> checkIfEmailVerified(FirebaseUser firebaseUser)</em></p><p><em>{</em></p><p><strong><em>if</em></strong><em> (firebaseUser != null) {</em></p><p><strong><em>return</em></strong><em> firebaseUser.isEmailVerified();</em></p><p><em>}</em></p><p><strong><em>return</em></strong><em> </em><strong><em>false</em></strong><em>;</em></p><p><em>}</em></p><p>To reset password we can send email on registered email address</p><p><strong><em>protected</em></strong><em> </em><strong><em>final</em></strong><em> </em><strong><em>void</em></strong><em> resetPassword(String emailId,</em><strong><em>final</em></strong><em> CallBack callback){</em></p><p><em>AUTH.sendPasswordResetEmail(emailId)</em></p><p><em>.addOnCompleteListener(</em><strong><em>new</em></strong><em> OnCompleteListener() {</em></p><p><em>@Override</em></p><p><strong><em>public</em></strong><em> </em><strong><em>void</em></strong><em> onComplete(@NonNull Task task) {</em></p><p><strong><em>if</em></strong><em> (task.isSuccessful()) {</em></p><p>Toast.makeText(getApplicationContext(),”Success”,Toast.LENGHT_LONG).show();</p><p><em>} </em><strong><em>else</em></strong><em> {</em></p><p>Toast.makeText(getApplicationContext(),,task.getException()).getMessage(),Toast.LENGHT_LONG).show();</p><p><em>}</em></p><p><em>}</em></p><p><em>});</em></p><p><em>}</em></p><p>To SignOut we can use firebase signOut function like below:</p><p><strong><em>protected</em></strong><em> </em><strong><em>final</em></strong><em> </em><strong><em>void</em></strong><em> authSignOut(</em><strong><em>final</em></strong><em> CallBack callback) {</em></p><p><em>FirebaseAuth.AuthStateListener authStateListener = firebaseAuth -&gt; {</em></p><p><strong><em>if</em></strong><em> (AUTH.getCurrentUser() == null) {</em></p><p><em>callback.onSuccess(firebaseAuth);</em></p><p><em>}</em></p><p><em>};</em></p><p><em>AUTH.addAuthStateListener(authStateListener);</em></p><p><em>AUTH.signOut();</em></p><p><em>}</em></p><p>Like this so many features are available in firebase we can do many more things using firebase.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1cf19efd824" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Multiple Themes in one application (Android)]]></title>
            <link>https://morepriyanka1794.medium.com/multiple-themes-in-one-application-android-acc1236cb92b?source=rss-374f26f06c1a------2</link>
            <guid isPermaLink="false">https://medium.com/p/acc1236cb92b</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-design]]></category>
            <category><![CDATA[themes]]></category>
            <category><![CDATA[android-theme]]></category>
            <dc:creator><![CDATA[Priyanka More]]></dc:creator>
            <pubDate>Sat, 01 May 2021 06:09:01 GMT</pubDate>
            <atom:updated>2021-05-01T06:09:01.666Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/908/0*0Hw6_dt7z_dses3U" /></figure><p>Image if we can change the color of application as per our choice isn’t it interesting?</p><p>Yes. It is very interesting.</p><p>Multiple themes app means users have the option to set application color as per their choice. Here we will see how we can do this….</p><p><strong>Add Color codes in <em>Colors.xml</em> files:</strong></p><p><strong>&lt;resources&gt;</strong></p><p><strong>&lt;color name=”colorAccent”&gt;#FFBB86FC&lt;/color&gt;</strong></p><p><strong>&lt;color name=”colorPrimary”&gt;#FF6200EE&lt;/color&gt;</strong></p><p><strong>&lt;color name=”colorPrimaryDark”&gt;#FF3700B3&lt;/color&gt;</strong></p><p><strong>&lt;color name=”headingTextColor”&gt;#FF03DAC5&lt;/color&gt;</strong></p><p><strong>&lt;color name=”descriptionTextColor”&gt;#FF018786&lt;/color&gt;</strong></p><p><strong>&lt;color name=”black”&gt;#FF000000&lt;/color&gt;</strong></p><p><strong>&lt;color name=”white”&gt;#FFFFFFFF&lt;/color&gt;</strong></p><p><strong>&lt;color name=”blue”&gt;#005980&lt;/color&gt;</strong></p><p><strong>&lt;color name=”yellow”&gt;#ffff00&lt;/color&gt;</strong></p><p><strong>&lt;color name=”green”&gt;#73e600&lt;/color&gt;</strong></p><p><strong>&lt;color name=”red”&gt;#FF0000&lt;/color&gt;</strong></p><p><strong>&lt;color name=”pink”&gt;#ff8da1&lt;/color&gt;</strong></p><p><strong>&lt;/resources&gt;</strong></p><p><strong>Create attrs.xml file:</strong></p><p>In attrs files add colors which we want to change dynamically, like below..</p><p>&lt;<strong>attr name=”colorPrimary” format=”color”</strong>/&gt;</p><p>&lt;<strong>attr name=”colorPrimaryDark” format=”color”</strong>/&gt;</p><p>&lt;<strong>attr name=”colorAccent” format=”color”</strong>/&gt;</p><p>&lt;<strong>attr name=”headingTextColor” format=”color”</strong>/&gt;</p><p>&lt;<strong>attr name=”descriptionTextColor” format=”color”</strong>/&gt;</p><p><strong>Choose color options:</strong></p><p>We will create multiple buttons for the user to choose color as per their choice.</p><p>On <em>activity_main.xml</em> add a UI for choosing colors:</p><p><strong>Important Note: </strong>use “<strong>?attr/color_name</strong>” where we want to set dynamic color change of view.</p><p>Ex: <strong><em>android:background=”?attr/colorPrimary” / android:textColor=”?attr/headingTextColor”</em></strong></p><p><em>&lt;?</em><strong>xml version=”1.0&quot; encoding=”utf-8&quot;</strong><em>?&gt;</em></p><p>&lt;<strong>androidx.constraintlayout.widget.ConstraintLayout xmlns:android=”http://schemas.android.com/apk/res/android&quot;</strong></p><p><strong>android:layout_width=”match_parent”</strong></p><p><strong>android:layout_height=”match_parent”</strong></p><p><strong>xmlns:app=”http://schemas.android.com/apk/res-auto&quot;</strong></p><p><strong>xmlns:tools=”http://schemas.android.com/tools&quot;</strong></p><p><strong>tools:context=”.MainActivity”</strong>&gt;</p><p>&lt;<strong>androidx.appcompat.widget.Toolbar</strong></p><p><strong>android:id=”@+id/toolbar”</strong></p><p><strong>android:layout_width=”match_parent”</strong></p><p><strong>android:layout_height=”wrap_content”</strong></p><p><strong>android:background=”?attr/colorPrimary”</strong></p><p><strong>app:title=”Multiple Themes”</strong></p><p><strong>app:titleTextColor=”@color/white”</strong></p><p><strong>app:layout_constraintBottom_toBottomOf=”parent”</strong></p><p><strong>app:layout_constraintBottom_toTopOf=”@id/linearLayout”</strong></p><p><strong>app:layout_constraintEnd_toEndOf=”parent”</strong></p><p><strong>app:layout_constraintStart_toStartOf=”parent”</strong>&gt;</p><p>&lt;/<strong>androidx.appcompat.widget.Toolbar</strong>&gt;</p><p>&lt;<strong>LinearLayout</strong></p><p><strong>android:id=”@+id/linearLayout”</strong></p><p><strong>android:layout_width=”match_parent”</strong></p><p><strong>android:layout_height=”0dp”</strong></p><p><strong>android:orientation=”vertical”</strong></p><p><strong>app:layout_constraintEnd_toEndOf=”parent”</strong></p><p><strong>app:layout_constraintStart_toStartOf=”parent”</strong></p><p><strong>app:layout_constraintTop_toBottomOf=”@id/toolbar”</strong></p><p><strong>android:layout_margin=”20dp”</strong>&gt;</p><p>&lt;<strong>androidx.cardview.widget.CardView</strong></p><p><strong>android:layout_width=”match_parent”</strong></p><p><strong>android:layout_height=”wrap_content”</strong></p><p><strong>app:cardMaxElevation=”10dp”</strong>&gt;</p><p>&lt;<strong>LinearLayout</strong></p><p><strong>android:layout_width=”match_parent”</strong></p><p><strong>android:layout_height=”wrap_content”</strong></p><p><strong>android:orientation=”vertical”</strong></p><p><strong>android:padding=”10dp”</strong></p><p>&gt;</p><p>&lt;<strong>TextView</strong></p><p><strong>android:layout_width=”match_parent”</strong></p><p><strong>android:layout_height=”wrap_content”</strong></p><p><strong>android:text=”@string/multiple_themes_heading”</strong></p><p><strong>android:layout_gravity=”center_horizontal”</strong></p><p><strong>android:gravity=”center”</strong></p><p><strong>android:textSize=”20sp”</strong></p><p><strong>android:padding=”10dp”</strong></p><p><strong>android:textColor=”?attr/headingTextColor”</strong>&gt;</p><p>&lt;/<strong>TextView</strong>&gt;</p><p>&lt;<strong>TextView</strong></p><p><strong>android:layout_width=”match_parent”</strong></p><p><strong>android:layout_height=”wrap_content”</strong></p><p><strong>android:layout_gravity=”center_horizontal”</strong></p><p><strong>android:textSize=”12sp”</strong></p><p><strong>android:text=”@string/here_we_will_see_how_all_colors_get_s_changes_as_per_our_themes_heading_text_color_toolbar_and_description_text_color_everything_is_different_in_every_theme”</strong></p><p><strong>android:textColor=”?attr/descriptionTextColor”</strong></p><p>&gt;</p><p>&lt;/<strong>TextView</strong>&gt;</p><p>&lt;/<strong>LinearLayout</strong>&gt;</p><p>&lt;/<strong>androidx.cardview.widget.CardView</strong>&gt;</p><p>&lt;<strong>LinearLayout</strong></p><p><strong>android:layout_width=”match_parent”</strong></p><p><strong>android:layout_height=”wrap_content”</strong></p><p><strong>android:orientation=”vertical”</strong></p><p><strong>android:layout_marginTop=”20dp”</strong>&gt;</p><p>&lt;<strong>Button</strong></p><p><strong>android:id=”@+id/btn_blue”</strong></p><p><strong>android:layout_width=”match_parent”</strong></p><p><strong>android:layout_height=”wrap_content”</strong></p><p><strong>android:text=”@string/blue_theme”</strong></p><p><strong>android:backgroundTint=”@color/blue”</strong>&gt;</p><p>&lt;/<strong>Button</strong>&gt;</p><p>&lt;<strong>Button</strong></p><p><strong>android:id=”@+id/btn_yellow”</strong></p><p><strong>android:layout_width=”match_parent”</strong></p><p><strong>android:layout_height=”wrap_content”</strong></p><p><strong>android:text=”@string/yellow_theme”</strong></p><p><strong>android:backgroundTint=”@color/yellow”</strong>&gt;</p><p>&lt;/<strong>Button</strong>&gt;</p><p>&lt;<strong>Button</strong></p><p><strong>android:id=”@+id/btn_green”</strong></p><p><strong>android:layout_width=”match_parent”</strong></p><p><strong>android:layout_height=”wrap_content”</strong></p><p><strong>android:text=”@string/green_theme”</strong></p><p><strong>android:backgroundTint=”@color/green”</strong>&gt;</p><p>&lt;/<strong>Button</strong>&gt;</p><p>&lt;<strong>Button</strong></p><p><strong>android:id=”@+id/btn_red”</strong></p><p><strong>android:layout_width=”match_parent”</strong></p><p><strong>android:layout_height=”wrap_content”</strong></p><p><strong>android:text=”@string/red_theme”</strong></p><p><strong>android:backgroundTint=”@color/red”</strong>&gt;</p><p>&lt;/<strong>Button</strong>&gt;</p><p>&lt;<strong>Button</strong></p><p><strong>android:id=”@+id/btn_pink”</strong></p><p><strong>android:layout_width=”match_parent”</strong></p><p><strong>android:layout_height=”wrap_content”</strong></p><p><strong>android:text=”@string/pink_theme”</strong></p><p><strong>android:backgroundTint=”@color/pink”</strong>&gt;</p><p>&lt;/<strong>Button</strong>&gt;</p><p>&lt;/<strong>LinearLayout</strong>&gt;</p><p>&lt;/<strong>LinearLayout</strong>&gt;</p><p>&lt;/<strong>androidx.constraintlayout.widget.ConstraintLayout</strong>&gt;</p><p>On <em>MainActivity</em> we will manage onClick of buttons and we will set setAppThemes:</p><p><em>What exactly we are doing here, on click of button We are saving selected themes in SharedPreferences,And calling recreate activity to refresh activity. After activity get refreshed from base activity we will get the selected theme.</em></p><p><strong>class </strong>MainActivity : BaseActivity(),View.OnClickListener {</p><p><strong>override fun </strong>onCreate(savedInstanceState: Bundle?) {</p><p><strong>super</strong>.onCreate(savedInstanceState)</p><p>setContentView(R.layout.<em>activity_main</em>)</p><p><strong>val </strong>btnBlue: Button = findViewById(R.id.<em>btn_blue</em>)</p><p><strong>val </strong>btnYellow: Button = findViewById(R.id.<em>btn_yellow</em>)</p><p><strong>val </strong>btnGreen: Button = findViewById(R.id.<em>btn_green</em>)</p><p><strong>val </strong>btnRed: Button = findViewById(R.id.<em>btn_red</em>)</p><p><strong>val </strong>btnPink: Button = findViewById(R.id.<em>btn_pink</em>)</p><p>btnBlue.setOnClickListener(<strong>this</strong>)</p><p>btnYellow.setOnClickListener(<strong>this</strong>)</p><p>btnGreen.setOnClickListener(<strong>this</strong>)</p><p>btnRed.setOnClickListener(<strong>this</strong>)</p><p>btnBlue.setOnClickListener(<strong>this</strong>)</p><p>btnPink.setOnClickListener(<strong>this</strong>)</p><p>}</p><p><strong>override fun </strong>onClick(v: View?) {</p><p><strong>when</strong>(v?.<em>id</em>){</p><p>R.id.<em>btn_blue </em>-&gt; {</p><p>SharedPreferenceUtil.putString(<em>SELECTED_THEME</em>, <em>BLUE_THEME</em>)</p><p>}</p><p>R.id.<em>btn_yellow </em>-&gt;{</p><p>SharedPreferenceUtil.putString(<em>SELECTED_THEME</em>, <em>YELLOW_THEME</em>)</p><p>}</p><p>R.id.<em>btn_green </em>-&gt;{</p><p>SharedPreferenceUtil.putString(<em>SELECTED_THEME</em>, <em>GREEN_THEME</em>)</p><p>}</p><p>R.id.<em>btn_pink </em>-&gt;{</p><p>SharedPreferenceUtil.putString(<em>SELECTED_THEME</em>, <em>PINK_THEME</em>)</p><p>}</p><p>R.id.<em>btn_red </em>-&gt; {</p><p>SharedPreferenceUtil.putString(<em>SELECTED_THEME</em>, <em>RED_THEME</em>)</p><p>}</p><p>}</p><p>recreate()</p><p>}</p><p>}</p><p>Here adding <em>BaseActvity </em>from base activity we will manage setAppTheme:</p><p><em>Here on Base activity we are calling setAppTheme, In the SetAppTheme function we are applying styles to our project by using “theme</em>.applyStyle<em>”. From onCreate whenever activity gets refreshed we will get the latest applied theme.</em></p><p><strong>open class </strong>BaseActivity : AppCompatActivity() {</p><p><strong>override fun </strong>onCreate(savedInstanceState: Bundle?) {</p><p><strong>super</strong>.onCreate(savedInstanceState)</p><p>setAppTheme(<strong>this</strong>)</p><p>}</p><p><strong>fun </strong>setAppTheme(context: Context) {</p><p>Log.e(<strong>“selected Theme”</strong>,<strong>””</strong>+SharedPreferenceUtil.getString(<em>SELECTED_THEME</em>, <em>DEFAULT_THEME</em>))</p><p><strong>when </strong>(SharedPreferenceUtil.getString(<em>SELECTED_THEME</em>, <em>DEFAULT_THEME</em>)) {</p><p><em>BLUE_THEME </em>-&gt; context.<em>theme</em>.applyStyle(R.style.<em>BlueTheme</em>, <strong>true</strong>)</p><p><em>YELLOW_THEME </em>-&gt; context.<em>theme</em>.applyStyle(R.style.<em>YellowTheme</em>, <strong>true</strong>)</p><p><em>GREEN_THEME </em>-&gt; context.<em>theme</em>.applyStyle(R.style.<em>GreenTheme</em>, <strong>true</strong>)</p><p><em>RED_THEME </em>-&gt; context.<em>theme</em>.applyStyle(R.style.<em>RedTheme</em>,<strong>true</strong>)</p><p><em>PINK_THEME </em>-&gt; context.<em>theme</em>.applyStyle(R.style.<em>PinkTheme</em>, <strong>true</strong>)</p><p><strong>else </strong>-&gt; {</p><p>context.<em>theme</em>.applyStyle(R.style.<em>DefaultTheme</em>, <strong>true</strong>)</p><p>}</p><p>}</p><p>}</p><p>}</p><p>Here we are using few constant values like below:</p><p><em>// Themes</em></p><p><strong>const val </strong><em>BLUE_THEME </em>= <strong>“BlueTheme”</strong></p><p><strong>const val </strong><em>YELLOW_THEME </em>= <strong>“YellowTheme”</strong></p><p><strong>const val </strong><em>GREEN_THEME </em>= <strong>“GreenTheme”</strong></p><p><strong>const val </strong><em>RED_THEME </em>= <strong>“Red Theme”</strong></p><p><strong>const val </strong><em>PINK_THEME </em>= <strong>“Pink Theme”</strong></p><p><strong>const val </strong><em>DEFAULT_THEME </em>= <strong>“DefaultTheme”</strong></p><p><strong>const val </strong><em>SELECTED_THEME </em>= <strong>“selectedTheme”</strong></p><p>We can see the result will be like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/0*mluwadSDvorFNM_7" /><figcaption>Blue Theme</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/0*KO6CRIVgI88BHTlQ" /><figcaption>Yellow Theme</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/0*tEPknGdpkBIww_rS" /><figcaption>Green Theme</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/0*ga2E_9KhO6pYk3Cy" /><figcaption>Red Theme</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/0*belZm9JePAZ0O2yz" /><figcaption>Pink Theme</figcaption></figure><p>.</p><p><strong>Hope it will be helpful to you!!!😊</strong></p><p><strong><em>Priyanka More.</em></strong></p><p><strong><em>I am an Android developer with around 3+ years of experience developing Android applications with core functionality. I have in-depth knowledge of Java and ReactNative. I like to learn new things and share.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=acc1236cb92b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>