ad728

Wednesday, December 7, 2016

AIDE Tutorial - 7 Toast Button

AIDE Tutorial - 7 Toast Button





Toast Button will help to appear toast when the button is clicked. In this app, we add onClick method to the button whenever the button is clicked a toast message will appear. 
        To show toast we will use a normal Button.
Add a button on XML
First of all add a button. Lets add a normal button.

<Button
        android:onClick="Click"
        android:text="Click Me"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />



Java
Import these on Java
import android.view.View;
import android.widget.Toast;

Add after R.layout.main
public void Click (View view){
     Toast.makeText(
getApplicationContext(),
"you clicked",
Toast.LENGTH_SHORT
).show();


After adding this on Main Activity.java you need to build the app. When you click button a small toast will appear which says you clicked.
Toast.LENGTH_SHORT instead of this you can also write Toast.LENGTH_LONG this will shows toast for longer duration.
Share:

0 comments:

Post a Comment

Total Pageviews

Sponsor

Sponsor

ad300