For a custom popup, create one XML file named
cust_toast_layout.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/toast_layout_root" android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="45dp" > <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@android:color/white" android:textSize="25sp" android:textStyle="bold" android:gravity="center" android:paddingTop="200dp"/> </LinearLayout>
Then in the java file where you want this popup to be added below the code
LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.cust_toast_layout, (ViewGroup)findViewById(R.id.toast_layout_root)); TextView text = (TextView) layout.findViewById(R.id.text); //text.setText("Excellent !!!"); text.setBackgroundResource(R.drawable.right_ans); Toast toast = new Toast(getApplicationContext()); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(Toast.LENGTH_SHORT); toast.setView(layout); toast.show();
In buttonclick, you can call one method and include this code in this method. You can make changes according to your requirements by editing in an XML file.
source share