Echo

FIND WHAT YOU WANT.

Subscribe Us

Ads Here

Tech

HOW TO CREATE A TOAST MESSAGE IN ANDROID
A toast message in android looks like the image below.



Steps:
  1. Create a new android application call it Toast Message.
  2. Call the class MainActivity.
package com.example.myapplication;



import android.app.Activity;
import android.widget.TextView;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import com.example.myapplication.R;


public class MainActivity extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);



}
public void viewToast(View view){
Toast.makeText(this,”This is a long toast message”,Toast.LENGTH_LONG).show();



Toast.makeText(this,”This is a short toast message”,Toast.LENGTH_SHORT).show();
}


}
3. Go to the activity_main.XML and create an layout for your app like the one below.

4. Your application is now ready and should work correctly.In case of any questions, I'm ready to answer.

No comments:

Post a Comment