Design Of Android Using Android Studio

Introduction

 
In the current scenario, most people use Android smartphones. I will show you how to change GUI components in an Android, using  Android Studio. Android is the kernel based operating system. It allows the user to modify GUI components and the source code.
 
Requirements

Steps to be followed are given below

 
Carefully follow the steps given below to learn how to change GUI components in an Android and I have included the source code given below.
 
Step 1
 
Open Android Studio. Start the new project.
 
android
 
Step 2
 
Put the Application name and company domain. If you wish to use C++ to code the project, mark the Include C++ support, followed by clicking Next.
 
android
 
Step 3
 
Select Android minimum SDK. Afterwards, you chose the minimum SDK and it will show the approximate percentage of people who use SDK , followed by clicking Next.
 
android
 
Step 4
 
Choose the basic activity, followed by clicking Next.
 
android
 
Step 5
 
Put the activity name and layout name. Android Studio basically takes Java class name from what you provide as the activity name.
 
android
 
Step 6
 
This is the default activity design for the basic activity layout.
 
android
 
Step 7
 
Go to activity_design.xml then click the text bottom.
 
android
 
Step 8
 
Into the activity_design.xml, copy and paste the code given below.
 
activity_design.xml code
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  android:layout_height="fill_parent"  
  4.     android:orientation="vertical" >  
  5.     <TextView  
  6.         android:id="@+id/textView1"  
  7.         android:layout_width="match_parent"  
  8.         android:layout_height="wrap_content"  
  9.         android:layout_margin="20sp"  
  10.         android:gravity="center"  
  11.         android:text="DESIGN ANDROID"  
  12.         android:textSize="20sp"  
  13.         android:textStyle="italic" ></TextView>  
  14.     <Button  
  15.         android:id="@+id/button1"  
  16.         android:layout_width="match_parent"  
  17.         android:layout_height="wrap_content"  
  18.         android:gravity="center"  
  19.         android:text="Change font size"  
  20.         android:textSize="20sp" />  
  21.     <Button  
  22.         android:id="@+id/button2"  
  23.         android:layout_width="match_parent"  
  24.         android:layout_height="wrap_content"  
  25.         android:gravity="center"  
  26.         android:text="Change color"  
  27.         android:textSize="20sp" />  
  28.     <Button  
  29.         android:id="@+id/button3"  
  30.         android:layout_width="match_parent"  
  31.         android:layout_height="wrap_content"  
  32.         android:gravity="center"  
  33.         android:text="Change font"  
  34.         android:textSize="20sp" />  
  35. </LinearLayout>  
android
 
Step 9
 
This is our user interface of the Application
 
android
 
Step 10
 
Into the DesignActivity.java, copy and paste the code given below. Do not replace your package name.
 
DesignActivity.java code
  1. package ganeshannt.designandroid;  
  2.   
  3. //import android.R;  
  4. import android.app.Activity;  
  5. import android.graphics.Color;  
  6. import android.graphics.Typeface;  
  7. import android.os.Bundle;  
  8. import android.view.View;  
  9. import android.widget.Button;  
  10. import android.widget.TextView;  
  11. public class DesignActivity extends Activity  
  12. {  
  13.     float font =24;  
  14.     int i=1;  
  15.     @Override  
  16.     public void onCreate(Bundle savedInstanceState)  
  17.     {  
  18.         super.onCreate(savedInstanceState);  
  19.         setContentView(R.layout.activity_design);  
  20.         final TextView t1=(TextView) findViewById(R.id.textView1);  
  21.         Button  b1 = (Button) findViewById(R.id.button1);  
  22.         b1.setOnClickListener(new View.OnClickListener()  
  23.         {  
  24.             public void onClick(View view)  
  25.             {  
  26.                 t1.setTextSize(font);  
  27.                 font=font+4;  
  28.                 if(font==40)  
  29.                     font=20;  
  30.             }  
  31.         });  
  32.         Button  b2 = (Button) findViewById(R.id.button2);  
  33.         b2.setOnClickListener(new View.OnClickListener()  
  34.         {  
  35.             public void onClick(View view)  
  36.             {  
  37.                 switch(i)  
  38.                 {  
  39.                     case 1:  
  40.                         t1.setTextColor(Color.parseColor("#0000FF"));  
  41.                         break;  
  42.                     case 2:  
  43.                         t1.setTextColor(Color.parseColor("#00FF00"));  
  44.                         break;  
  45.                     case 3:  
  46.                         t1.setTextColor(Color.parseColor("#FF0000"));  
  47.                         break;  
  48.                     case 4:  
  49.                         t1.setTextColor(Color.parseColor("#800000"));  
  50.                         break;  
  51.                 }  
  52.                 i++;  
  53.                 if(i==5)  
  54.                     i=1;  
  55.             }  
  56.         });  
  57.     }  
  58. }  
android
 
Step 11
 
Click Build bottom and make the project. Now, your project compilation process is going on. Any error found in your project will be shown to you.
 
android
 
Step 12
 
Click run botton. Your emulator will start, followed by running your Application.
 
android
 
Deliverables
 
Proceed as shown.
 
android
 
android
 
android
 
android
 
If you have any doubts, just comment below.


Similar Articles