ToastActivity.java
------------------------------------------------
///////////////////////////////////////////////////////////
package home.toast;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
public class ToastActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.cust_toast_layout,
(ViewGroup) findViewById(R.id.relativeLayout1));
Toast toast = new Toast(this);
toast.setView(view);
toast.show();
}
}
///////////////////////////////////////////////////////////
cust_toast_layout.xml
---------------------------------------------------
///////////////////////////////////////////////////////////////
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/relativeLayout1"
android:background="@android:color/white">
<TextView
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/textView1" android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="Paresh N. Mayani"
android:gravity="center"
android:textColor="@android:color/black">
</TextView>
<ImageView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:src="@drawable/images"
android:layout_below="@+id/textView1"
android:layout_margin="5dip"
android:id="@+id/imageView1">
</ImageView>
<TextView
android:id="@+id/textView2"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="This is the demo of Custom Toast Notification"
android:gravity="center"
android:layout_below="@+id/imageView1"
android:textColor="@android:color/black">
</TextView>
</RelativeLayout>
////////////////////////////////////////////////////////////////
No comments:
Post a Comment