banner



How To Create An Animation That Changes Background Color For The Page

How do you lot breathing the change of background color of a view on Android?


This case demonstrates how do I animate the alter of groundwork color of a View on android.

Footstep 1 − Create a new projection in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.

Step 2 − Add the following code to res/layout/activity_main.xml.

<?xml version="1.0" encoding="utf-eight"?> <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/relativeLayout"    android:padding="8dp"    tools:context=".MainActivity">    <Push button       android:id="@+id/button"       android:text="Breathing background colour"       android:layout_width="wrap_content"       android:layout_height="wrap_content"       android:layout_above="@id/textView"       android:layout_centerInParent="truthful"       android:layout_marginBottom="15dp"/>    <TextView       android:id="@+id/textView"       android:layout_width="wrap_content"       android:layout_height="wrap_content"       android:textSize="36sp"       android:textStyle="bold"       android:text="Changing Background color of this view."       android:layout_centerInParent="truthful" /> </RelativeLayout>

Step three − Add the post-obit code to src/MainActivity.coffee

import androidx.appcompat.app.AppCompatActivity; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.TransitionDrawable; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    TextView textView;    Push button;    @Override    protected void onCreate(Packet savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       push button = findViewById(R.id.button);       textView = findViewById(R.id.textView);       button.setOnClickListener(new View.OnClickListener() {          @Override          public void onClick(View v) {             ColorDrawable[] colorDrawables = {new ColorDrawable(Color.Red),             new ColorDrawable(Colour.Blueish), new ColorDrawable(Color.GREEN)};             TransitionDrawable transitionDrawable = new TransitionDrawable(colorDrawables);             textView.setBackground(transitionDrawable);             transitionDrawable.startTransition(2000);          }       });    } }

Step iv − Add the following code to androidManifest.xml

<?xml version="i.0" encoding="utf-viii"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" bundle="app.com.sample">    <awarding       android:allowBackup="true"       android:icon="@mipmap/ic_launcher"       android:characterization="@string/app_name"       android:roundIcon="@mipmap/ic_launcher_round"       android:supportsRtl="true"       android:theme="@mode/AppTheme">       <action android:name=".MainActivity">          <intent-filter>             <activeness android:proper name="android.intent.action.MAIN" />             <category android:proper noun="android.intent.category.LAUNCHER" />          </intent-filter>       </activity>    </application> </manifest>

Let's endeavour to run your application. I assume y'all have connected your actual Android Mobile device with your computer. To run the app from android studio, open one of your project'due south activity files and click Run Play Icon icon from the toolbar. Select your mobile device every bit an choice and then check your mobile device which will display your default screen −


Click here to download the project code.

raja

Published on 11-Sep-2019 12:13:32

  • Related Questions & Answers
  • How do you lot breathing the alter of background color of a view on Android using Kotlin?
  • How do you lot animate the change of background color of a view on iOS?
  • How to change the background color of ListView items on Android?
  • How to change the background color of ListView items on Android Kotlin?
  • How to animate a alter in background color using jQuery on mouseover?
  • How to change the background color of ListView items on Android using Kotlin?
  • How to set background color of a view in Android App
  • How do I modify the background color of the ActionBar of an ActionBarActivity?
  • How to change the background color of the options menu in Android?
  • How to modify background color of TableView items on iOS?
  • Change the background color of a push with CSS
  • How to alter the background color of a Treeview in Tkinter?
  • How to alter the background color of a tkinter Canvas dynamically?
  • How to ready background color of a View in iOS App?
  • Change text color based on a brightness of the covered background expanse in HTML?

How To Create An Animation That Changes Background Color For The Page,

Source: https://www.tutorialspoint.com/how-do-you-animate-the-change-of-background-color-of-a-view-on-android

Posted by: albrittonoughted2001.blogspot.com

0 Response to "How To Create An Animation That Changes Background Color For The Page"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel