Saturday 14 December 2013

Custom Toast

1) in Activity.java
==============
final View toastView = getLayoutInflater().inflate(
R.layout.custom_toast,(ViewGroup) findViewById(R.id.toastLayout));
ImageView imageView = (ImageView) toastView
.findViewById(R.id.image);
imageView.setImageResource(R.drawable.ic_info);

// imageView.setBackgroundDrawable(bitmapDrawable);
TextView textView = (TextView) toastView.findViewById(R.id.text);
textView.setText("Take a Clear photo of the Ticket");
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
toast = new Toast(HomeActivity.this);
toast.setGravity(Gravity.TOP, 0, 100);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(toastView);
toast.show();
}
}, 2000);

2) custom_toast.xml
==============
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toastLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@layout/roundborder"
    android:orientation="horizontal"
    android:padding="10dp" >

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_marginRight="1dp" />

    <TextView
        android:id="@+id/text"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:layout_marginRight="4dp"
        android:gravity="center"
        android:paddingLeft="5dip"
        android:text="Take a clear photo of the Ticket"
        android:textColor="#FFF"
        android:textSize="16dip" />

</LinearLayout>

No comments:

Post a Comment