Monday 7 January 2013

Custom Toast in Android

First Create New Android Project and after that add below xml file in res/layout folder and add below code into your MainActivity.java file.

toast.xml

<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="#ffffff" >
        
    <ImageView android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_marginRight="10dp" />

    <TextView android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:textColor="#FFF" />
    
</LinearLayout>

Add below code into your MainActivity.java file

MainActivity.java

LayoutInflater inflater = getLayoutInflater();

View layout = inflater.inflate(R.layout.toast_layout, (ViewGroup) findViewById(R.id.toast_layout_root));
 
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.android);
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("Hello! This is a custom toast!");
 
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();

Enjoy  :-)

Don’t forget to provide feedback or follow this blog, if you find this blog is useful.

How To Send Email In Android

Write below code into your activity file for send Email from Android Application.

Java Code:-


Intent mAndroidEmailIntent = new Intent (android.content.Intent.ACTION_SEND);
String aEmailList[] = { "android@gmail.com","android@yahoomail.com" };
mAndroidEmailIntent.putExtra (android.content.Intent.EXTRA_EMAIL, aEmailList);
mAndroidEmailIntent.putExtra (android.content.Intent.EXTRA_SUBJECT, "Mail Subject");
mAndroidEmailIntent.setType ("plain/text");
mAndroidEmailIntent.putExtra (android.content.Intent.EXTRA_TEXT, "Email From My Android App");
startActivity (mAndroidEmailIntent);

Enjoy :-)

Don’t forget to provide feedback or follow this blog, if you find this blog is useful.