ToastDemo.JAVA:
package com.android.Toast;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;
public class ToastDemo extends Activity {
private EditText mET;
private Button mBtn;
private Toast mtoast;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mET=(EditText)findViewById(R.id.mET);
mBtn=(Button)findViewById(R.id.mBtn);
mBtn.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v){
mtoast=Toast.makeText(getApplicationContext(),"you writen:"+
mET.getText().toString(),Toast.LENGTH_LONG);
mtoast.setGravity(Gravity.TOP, 0, 0);
LinearLayout toastView=(LinearLayout)mtoast.getView();
ImageView mImage=new ImageView(getApplicationContext());
mImage.setImageResource(R.drawable.icon);
toastView.addView(mImage,0);
mtoast.show();
mET.setText("");
}
});
}
}
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<EditText
android:id="@+id/mET"
android:layout_width="180px"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/mBtn"
android:layout_width="100px"
android:layout_height="wrap_content"
android:text="@string/BtnText"
/>
</LinearLayout>
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.Toast"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ToastDemo"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="7" />
</manifest>