Skip to content

Instantly share code, notes, and snippets.

@PepDevils
Created February 14, 2017 16:20
Show Gist options
  • Select an option

  • Save PepDevils/8df664620b02ab323a347cb0caf29409 to your computer and use it in GitHub Desktop.

Select an option

Save PepDevils/8df664620b02ab323a347cb0caf29409 to your computer and use it in GitHub Desktop.
//java
static void PepeToast(AppCompatActivity a, String message){
LayoutInflater inflater = a.getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_layout, (ViewGroup) a.findViewById(R.id.toast_layout_root));
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText(message);
Toast toast = new Toast(a);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
//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="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:background="@drawable/rounded_desc"
>
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textStyle="bold"
android:textColor="@color/colorPrimary" />
</LinearLayout>
//@drawable/rounded_desc
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:thickness="1dp"
android:shape="rectangle">
<solid android:color="@color/colorPrimaryDark" />
<corners android:radius="6dp" />
</shape>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment