Android For Freshers
Toast Example In Android
Java Code(ToastAct )
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class ToastAct extends Activity {
EditText et1;
@ Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_toast);
et1=(EditText)findViewById(R.id.et1);
}
public void next(View v) {
String name = et1.getText().toString().trim();
Toast.makeText(ToastAct.this, name, Toast.LENGTH_SHORT).show();
}
}
Layout XML Code(activity_toast)
<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout 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:orientation=”vertical”
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.andro.tech.androidproject.ToastAct”>
<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:textSize=”@dimen/textsize”
android:textStyle=”bold”
android:layout_gravity=”center”
android:text=”@string/toasttext”
android:layout_marginBottom=”120dp” />
<EditText
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:hint=”Enter Text”
android:id=”@+id/et1″
android:gravity=”center”
android:layout_marginBottom=”30dp”/>
<Button
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”Click For Toast”
android:onClick=”next”
android:layout_marginBottom=”110dp”/>
<Button
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”@string/sourcecode”
android:background=”@color/bgcolor”
android:layout_gravity=”bottom”
android:textStyle=”bold”
android:textColor=”@color/text”
android:onClick=”view1″
android:layout_marginBottom=”10dp”/>
</LinearLayout>
Output:
Android Toast snippet source code download
For More Android Programs –Click Here
Follow Us – Never Miss Update
Fb/Page, Twitter, Google+, Instagram, Pinterest
Related Search
Android Toast snippet source code download, Android Toast activity source code, android toast java code, toast example android program, android toast java code snippet source download