Android Programming Lab Guide
Android Programming Lab Guide
April – 2024
NAME :
REG. NO :
SEMESTER : VI
1
SRI RAMAKRISHNA MISSION VIDYALAYA
COLLEGE OF ARTS AND SCIENCE
[AUTONOMOUS]
2
INDEX
3
Ex No. 1
Edit Text and Text View
AIM:
To create the android program to Enter the Text and Display the Text using Text and
Button Widget in ecplise android sdk package.
Algorithm:
1. Start the process.
3. Create edit text for website url ,button and web view for load.
4. Type the code in [Link] file to Enter the Text into Display below by Click
the button
4
[Link]
@Override
protected void onCreate(Bundle savedInstancedState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
b1=(Button)findViewById([Link].button1);
e1=(EditText)findViewById([Link].editText1);
t1=(TextView)findViewById([Link].textView2);
[Link](this);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String str=[Link]().toString();
[Link](str);
}
activity_main.xml
<EditText
android:id=”@+id/editText1”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_alighParentLeft=”true”
android:layout_alighParentTop=”true”
android:ems=”10” >
<requestFocus />
</EditText>
<Button
android:id=”@+id/button1”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
5
android:layout_alignLeft=”@id/editText1”
android:layout_below=”@id/editText1”
android:layout_marginLeft=”67dp”
android:layout_marginTop=”43dp”
android:text=”Go: />
<EditText
android:id=”@+id/editText2”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_alighParentLeft=”true”
android:layout_below=”@+id/button1”
android:layout_marginTop=”37dp”
android:text=”Your enter text is:”
android:textAppearance=”?android:attr/textAppearanceMedium” />
<requestFocus />
</EditText>
</RelativeLayout>
Output:
Result
Thus the Program was Successfully Executed and Verified
6
Ex No. 2
WEBVIEW USING LOAD URL
AIM:
To create the android program to load the website in the web view using android sdk
package.
Algorithm:
9. Create edit text for website url ,button and web view for load.
11. Get the website url as input value from the edit text boxe.
13. Load the website url in the webview by calling loadUrl() method.
7
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
MyWeb = (WebView) findViewById([Link]);
[Link]().setJavaScriptEnabled(true);
[Link]().setSaveFormData(true);
[Link]("[Link]
}
}
activity_main.xml
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="[Link]" >
<WebView
android:id="@+id/WebView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
Android [Link]:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="[Link]
package="[Link]"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
8
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="[Link]"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="[Link]" />
</manifest>
Output:
Result:
Thus the Program was Successfully Executed and Verified
9
Ex No. 3
Passing values Over Pages
AIM:
To create the android program to pass the form values from one page to another page
using android sdk package.
Algorithm:
project.
3. Create two edit text for user name and password and button for send.
5. Get the username and password as input values from the edit text boxes.
8. Create a sub activity and second xml file for the second form.
10
[Link]
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate([Link], menu);
11
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in [Link].
int id = [Link]();
if (id == [Link].action_settings) {
return true;
}
return [Link](item);
}
}
Acitivity_main.xml
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="[Link]" >
<EditText
android:id="@+id/edt_username"
android:layout_width="match_parent"
12
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="41dp"
android:ems="10"
android:hint="Username" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/edt_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/edt_username"
android:layout_centerHorizontal="true"
android:layout_marginTop="28dp"
android:ems="10"
android:hint="Password"
android:inputType="textPassword" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/edt_password"
android:layout_centerHorizontal="true"
android:layout_marginTop="27dp"
android:onClick="calllogin"
android:text="Login" />
13
</RelativeLayout>
[Link]
Activity_second.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="116dp"
android:layout_marginTop="70dp"
14
android:text="TextView" />
</RelativeLayout>
Output:
Result:
Thus the above program was Successfully Executed and Verified.
15
Ex No. 4
Addition of Two Numbers
AIM:
To create the addition of two numbers program using android sdk package.
Algorithm:
16
[Link]
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
Button btn = (Button) findViewById([Link].button1);
final EditText et1 = (EditText) findViewById([Link].editText1);
final EditText et2 = (EditText) findViewById([Link].editText2);
final TextView result = (TextView) findViewById([Link].textView1);
[Link](new OnClickListener() {
@Override
public void onClick(View v) {
int x = [Link]([Link]().toString());
int y = [Link]([Link]().toString());
int sum = x + y;
[Link]("The Sum of " + x + " and " + y + " is " + sum);
}
});
}
}
Acivity [Link]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Addition of 2 number" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" >
<requestFocus />
</EditText>
17
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="ADD" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
18
Output:
Result:
Thus the Program was Successfully Executed and Verified.
19
Ex No. 5
Context Menu
Aim
To create an android application program for Context Menu implementation
using Eclipse IDE
Algorithm
Step 1 : Start The Process
Step 2 : Create [Link] for displaying the Context Menu
Button, and Click Long Press
Step 3 : Add a code to XML File for Display the Context Menu
Button, and Click Long Press
Step 4 : In [Link] file add some block of code through source,
Override/Implement Methods as
OnCreateContextMenu(ContextMenu, View,
ContextMenuMethods)
Step 5 : Run this program by Right Click the Context Menu Android
Application Name in the Package Explorer.
Step 6 : Long Press the Context Menu Button it will display the Context
Menu in the Screen and By Clicked the button as Long Press it
will shows the Text SMS or Call by worked on Toast function.
20
Main [Link]
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
[Link](menu, v, menuInfo); [Link]("Select the
Action");
[Link]("Call");
[Link]("SMS");
}
@Override
public boolean onContextItemSelected(MenuItem item) {
// TODO Auto-generated method stub
if([Link]()=="Call")
{
[Link](getApplicationContext(), "Calling Code", 500).show();
}
21
else if([Link]()=="SMS")
{
[Link](getApplicationContext(), "SMS Sending", 500).show();
}
else
{
return false;
return true;
activity_context.xml
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent" android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".ContextActivity" >
<Button
android:id="@+id/buttonl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true" android:layout_alignParentTop="true"
android:layout_marginLeft="76dp"
android:layout_marginTop="80dp"
android:text="Context Menu" />
TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_below="@+id/button1"
android:layout_centerHorizontal="true"
android:text="Long Press in this buttont
android:textAppearance"?android:attr/textAppearance Small" />
</RelativeLayout>
22
Output
Result
Thus the Program was successfully Executed and Verified
23
Ex No. 6
Phone Call Using AVD
Aim :
To create the android program to make a phone call using AVD.
Algorithm :
Step 1 : Start The Process
Step 2 : Create Two Android Virtual Machines (AVD)
Step 3 : Start Two Android Virtual Machines Those Before , We Created
Step 4 : Start The Phone Call Application In First AVD
Step 5 : Dial The Second AVD’s Number in The Phone Call Application
Step 6 : Press The Call Button It Will Make a Call to second AVD
Step 7 : Stop The Process
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
protected void onCreate(Bundle savedInstanceState) {
24
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate([Link], menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in [Link].
int id = [Link]();
if (id == [Link].action_settings) {
return true;
}
return [Link](item);
}
}
25
Activity_main.xml
<RelativeLayout
xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="example. [Link]" >
</RelativeLayout>
Output :
26
Result
Thus the Program was Successfully Executed and Verified Successfully.
27
Ex No. 7
Notification
Aim :
To Create The Android Program To Make The Notification Demo in Using
AVD
Algorithm :
Step 1 : Start The Process
Step 2 : Create The New Android Application With Package
[Link]
Step 3 : Adding Button To Screen With Using Palatte Window In
activity_main.xml
Step 4 : Type The Code In [Link] File To Display
Notification By Touching The Button
Step 5 : Type The Code In Onclick() Method
NotificationManager notimanger =
(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
[Link] ncb = new [Link](this)
.setSmallIcon([Link].ic_launcher)
.setContentTitle("From John")
.setContentText("Welcome And Hi ....");
[Link](001,[Link]());
28
[Link]
package example.notification_text;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
b1 = (Button)findViewById([Link].button1);
t1 = (TextView)findViewById([Link].textView1);
[Link](this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate([Link], menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in [Link].
int id = [Link]();
29
if (id == [Link].action_settings) {
return true;
}
return [Link](item);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
try{
Activity_main.xml
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
30
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="example.notification_text.MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="106dp"
android:text="Simple Text Notification" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="TextView" />
</RelativeLayout>
Output :
31
Result
Thus the Program was Successfully Executed and Verified.
32
Ex No. 8
Check Internet Connection
Aim :
To Create the android program to using Check the internet connected or not
by using Eclipse IDE
Algorithm :
Step 1 : Start The Process
Step 2 : Create The New Android Application With Package [Link]
Step 3 : Create And Design The Screen Using EditText Using With Paletee
Window
Step 4 : Type The Code in [Link]
ConnectivityManager conn = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = [Link]();
if(ni!=null && [Link]()){
[Link]("Connected");
}
else{
[Link]("Not Connected");
}
Step 5 : Type The Code in [Link]
<uses-permission
android:name="[Link]"></uses-permission>
<uses-permission
android:name="[Link].ACCESS_NETWORK_STATE"></uses-
permission>
Step 6 : Press The Call Button It Will Make a Call to second AVD
Step 7 : Stop The Process
33
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends ActionBarActivity {
TextView t1;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
t1 = (TextView)findViewById([Link].textView1);
ConnectivityManager conn = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = [Link]();
if(ni!=null && [Link]()){
[Link]("Connected");
}
else{
[Link]("Not Connected");
}
}
@Override
34
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate([Link], menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in [Link].
int id = [Link]();
if (id == [Link].action_settings) {
return true;
}
return [Link](item);
}
}
Activity_main.xml
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="[Link]" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
35
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="90dp"
android:layout_marginTop="106dp"
android:text="TextView" />
</RelativeLayout>
[Link]
<uses-permission
android:name="[Link]"></uses-permission>
<uses-permission
android:name="[Link].ACCESS_NETWORK_STATE"></us
es-permission>
Output :
Result
Thus the Program was Successfully Executed and Verified.
36
Ex No. 9
Date Picker
Aim :
To Create the android program to select the date and view in textview by
using eclipse ide
Algorithm :
Step 1 : Start The Process
Step 2 : Create The New Android Application With Package [Link]
Step 3 : Create And Design The Screen Using TextView,Button,DatePicker
Using With Paletee Window
Step 4 : Type The Xml Code in activity_main.xml
<DatePicker
android:spinnersShown="true"
android:calendarViewShown="false"
android:layout_marginBottom="86dp" />
Step 5 : Type The Code in [Link]
public void onClick(View v)
{
// TODO Auto-generated method stub
[Link](getdate());
}
public String getdate()
{
StringBuffer data = new StringBuffer();
[Link]("Currect Date Is ");
[Link]([Link]()+"/");
[Link](([Link]()+1)+"/");
[Link]([Link]());
return [Link]();
}
Step 6 : Stop The Process
37
Activity_main.xml
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="[Link]" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="152dp"
android:text="Pick This Date" />
<DatePicker
android:id="@+id/datePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/button1"
android:layout_centerHorizontal="true"
android:spinnersShown="true"
android:calendarViewShown="false"
android:layout_marginBottom="86dp" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/datePicker1"
android:layout_below="@+id/button1"
android:layout_marginTop="54dp"
android:text="TextView" />
</RelativeLayout>
[Link]
38
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
b1 = (Button)findViewById([Link].button1);
d1 = (DatePicker)findViewById([Link].datePicker1);
t1 = (TextView)findViewById([Link].textView1);
[Link](this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate([Link], menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in [Link].
39
int id = [Link]();
if (id == [Link].action_settings) {
return true;
}
return [Link](item);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
[Link](getdate());
}
public String getdate(){
StringBuffer data = new StringBuffer();
[Link]("Currect Date Is ");
[Link](([Link]()+1)+"/");
[Link]([Link]()+"/");
[Link]([Link]());
return [Link]();
}
}
40
Output
Result
Thus the Program was Successfully Executed and Verified.
41
Ex No. 10
Button with Color Text
Aim :
To create the android program to select the button view in button name in
textview by using eclipse IDE.
Algorithm :
Step 1 : Start The Process
Step 3 : Create And Design The Screen Using Three Button Using With
Paletee Window
42
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
b1 = (Button)findViewById([Link].button1);
b2 = (Button)findViewById([Link].button2);
b3 = (Button)findViewById([Link].button3);
[Link](this);
[Link](this);
[Link](this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate([Link], menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
43
// as you specify a parent activity in [Link].
int id = [Link]();
if (id == [Link].action_settings) {
return true;
}
return [Link](item);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if([Link]()==[Link].button1){
Toast t = [Link]([Link],
[Link]()+"Clicked", Toast.LENGTH_SHORT);
[Link]([Link], 20, 20);
[Link]();
}
if([Link]()==[Link].button2){
Toast t = [Link]([Link],
[Link]()+"Clicked", Toast.LENGTH_SHORT);
[Link]([Link], 20, 20);
[Link]();
}
if([Link]()==[Link].button3){
Toast t = [Link]([Link],
[Link]()+"Clicked", Toast.LENGTH_SHORT);
[Link]([Link], 20, 20);
[Link]();
}
}
}
44
Activity_main.xml
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="[Link]" >
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/button2"
android:layout_marginLeft="90dp"
android:layout_marginTop="31dp"
android:background="@color/bgcolor"
android:padding="10sp"
android:text="blue"
android:textColor="@color/bblue"
android:textSize="30sp"
android:textStyle="bold" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button3"
android:layout_centerVertical="true"
android:background="@color/bgcolor"
android:padding="10sp"
android:text="green"
android:textColor="@color/bgreen"
android:textSize="30sp"
android:textStyle="bold" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
45
android:layout_height="wrap_content"
android:layout_above="@+id/button2"
android:layout_alignLeft="@+id/button2"
android:layout_marginBottom="32dp"
android:background="@color/bgcolor"
android:padding="10sp"
android:text="red"
android:textColor="@color/bred"
android:textSize="30sp"
android:textStyle="bold" />
</RelativeLayout>
[Link]
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">ButtonsWithColor</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="red">Red</string>
<string name="green">Green</string>
<string name="blue">Blue</string>
</resources>
[Link]
<color name="bred">#ff5733</color>
<color name="bgreen">#145A32</color>
<color name="bblue">#1B4F72</color>
<color name="bgcolor">#F7dc67</color>
46
Output :
Result
Thus the Program was Successfully Executed and Verified.
47