0% found this document useful (0 votes)
72 views

Lab Assignment-2

The document contains instructions for building several Android applications: 1. Create a "Hello World" application using Android Studio and display a Toast message. 2. Build an app with a TextView displaying "Hello World" and add background color and margins using XML resources. 3. Add an onClick listener to a button to change the TextView text when clicked.

Uploaded by

S.ganga priya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views

Lab Assignment-2

The document contains instructions for building several Android applications: 1. Create a "Hello World" application using Android Studio and display a Toast message. 2. Build an app with a TextView displaying "Hello World" and add background color and margins using XML resources. 3. Add an onClick listener to a button to change the TextView text when clicked.

Uploaded by

S.ganga priya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Assignment-2

1. Build your first simple Hello world application using android studio .
2. Build Hello world application using Toast in android studio .
File: MainActivity.java
package example.javatpoint.com.toast;  
  
import android.support.v7.app.AppCompatActivity;  
import android.os.Bundle;  
import android.widget.Toast;  
  
public class MainActivity extends AppCompatActivity {  
  
    @Override  
     protected void onCreate(Bundle savedInstanceState) {  
         super.onCreate(savedInstanceState);  
         setContentView(R.layout.activity_main);  
         //Displaying Toast with Hello Javatpoint  message  
       Toast.makeText(getApplicationContext(),"Hello Javatpoint",Toast.LENGTH_SHO
RT).show();  
     }  

 
3. Build an application that contains a TextView with value “Hello world”.
4. Create your own values in string.xml
1. Add background to textView created in above ques 3
a) Using hexadecimal value in xml layout
b) Using color.xml values
2. Add margins to TextView in ques3
a) Using hexadecimal value in xml layout
b) Using dimens.xml values
activity_main.xml
<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: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=".MainActivity">

<TextView
android:id="@+id/simpleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Before Clicking"
android:textColor="#f00"
android:textSize="25sp"
android:textStyle="bold|italic"
android:layout_marginTop="50dp"/>

<Button
android:id="@+id/btnChangeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#f00"
android:padding="10dp"
android:text="Change Text"
android:textColor="#fff"
android:textStyle="bold" />
</RelativeLayout>

 MainActivity.java

package example.abhiandriod.textviewexample;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); //set the layout
final TextView simpleTextView = (TextView)
findViewById(R.id.simpleTextView); //get the id for TextView
Button changeText = (Button) findViewById(R.id.btnChangeText); //get the
id for button
changeText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
simpleTextView.setText("After Clicking"); //set the text after
clicking button
}
});
}
}

OUTPUT:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy