Android Studio Day Night Animation


Build Gradle Project

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }

Android Studio Design Animation
 
Build Gradle Module

implementation 'com.github.Mahfa:DayNightSwitch:1.2'

Android Studio Design Animation


Main Activity

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/layout"
        tools:context=".design11part15">

    <com.mahfa.dnswitch.DayNightSwitch
            android:id="@+id/day_night_switch"
            android:layout_width="76dp"
            android:layout_height="40dp"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"/>

</RelativeLayout>

Android Studio Design Animation

Activity Main

package com.designapp

import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import kotlinx.android.synthetic.main.activity_design11part15.*

class design11part15 : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_design11part15)


        day_night_switch.setListener {
                isNight ->
            if(isNight)
            {
                Toast.makeText(this,"Good Night",Toast.LENGTH_SHORT).show()
                layout.setBackgroundColor(Color.parseColor("#34495e"))
                layout.setBackgroundResource(R.drawable.night)
            }
            else
            {
                Toast.makeText(this,"Good Morning",Toast.LENGTH_SHORT).show()
                layout.setBackgroundColor(Color.parseColor("#349Bdb"))
                layout.setBackgroundResource(R.drawable.morning)
            }
        }
    }
}



Subscribe to receive free email updates:

0 Response to "Android Studio Day Night Animation "

Post a Comment