Android Toast

Android Toast Example

MainCLASS

package com.example.malik.javatpoint;

import android.os.Bundle;
import android.app.Activity;
import android.view.Gravity;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

//Displaying Toast with Hello message
// Toast.makeText(getApplicationContext(),”Hello Malik Himani”,Toast.LENGTH_SHORT);
// or

Toast toast = Toast.makeText(getApplicationContext(),”Hello Malik Himani”,Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}

}

MainXML

<?xml version=”1.0″ encoding=”utf-8″?>
<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=”com.example.malik.javatpoint.MainActivity”
android:background=”#c70a0a”>

<EditText
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:inputType=”number”
android:ems=”10″
android:id=”@+id/etNum1″
android:layout_alignParentTop=”true”
android:layout_alignLeft=”@+id/etNum2″
android:layout_alignStart=”@+id/etNum2″
android:hint=”Num 1″ />

<EditText
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:inputType=”number”
android:ems=”10″
android:id=”@+id/etNum2″
android:layout_below=”@+id/etNum1″
android:layout_centerHorizontal=”true”
android:layout_marginTop=”62dp”
android:hint=”Num 2″ />

<Button
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”@string/sum”
android:id=”@+id/bSum”
android:layout_alignParentBottom=”true”
android:layout_centerHorizontal=”true”
android:layout_marginBottom=”141dp” />

<EditText
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:inputType=”number”
android:ems=”10″
android:id=”@+id/etNum3″
android:layout_centerVertical=”true”
android:layout_centerHorizontal=”true”
android:hint=”Num 3″ />

</RelativeLayout>

 

Output :

pic

 

 

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.