MAD Practical 7
MAD Practical 7
MAD Practical 7
Step 2: Open activity_main.xml and add following code. Here we will create a button and a
textview in Relative Layout.
<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="Hello"
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="Click here"
android:textColor="#fff"
android:textStyle="bold" />
</RelativeLayout>
Step 3: Open MainActivity.java and add the following code. Here we will change the text of
TextView after the user click on Button.
package myapplication.andriod.textviewexample;
Import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
Import android.os.Bundle;
Import android.view.View;
Import android.widget.Button;
Import android.widget.TextView;