Any one can tell me how to display this Message in Android. Registered Successfully Click To view Image
Asked
Active
Viewed 333 times
-3
-
1Read about Android Toast and setting custom layout for toast - https://developer.android.com/guide/topics/ui/notifiers/toasts.html – GaneshP Jul 05 '17 at 17:43
2 Answers
0
The class used to display temporary messages in android is called Toast.
The method to display a toast is as follows :-
Toast.makeText(context,"Your message to display",Toast.LENGTH_LONG).show();
Read up more on Toast here here. And to add images and customise the toast ( as shown in your image ) , you can refer to this answer.
Rohan Stark
- 2,346
- 9
- 16
0
I believe you should use a custom Toast.
Create a layout resource file. My resource file is named toast.xml, but name it whatever you want. Find an image of the green check, and save it to your app's drawable folder.
toast.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toast_layout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:background="#FFF" >
<ImageView android:id="@+id/image"
android:contentDescription="Green check mark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/green_check_mark"/>
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#FF8B8B8B"
android:text="Registered Successfully"/>
In your MainActivity.java
public void showCustomToast(String message) {
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast,
(ViewGroup) findViewById(R.id.toast_layout));
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText(message);
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
Just call showCustomToast("Registered Successfully) to show the Toast. Hope this helps.
an3
- 568
- 1
- 6
- 14