android 語音總機對話方塊:
1)Toast.makeText(Login.this, R.string.login_dialog_note, Toast.LENGTH_LONG).show();
2)自訂
public void showToast(){
LayoutInflater li=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view=li.inflate(R.layout.toast,null);
//把布局檔案toast.xml轉換成一個view
Toast toast=new Toast(this);
toast.setView(view);
//載入view,即顯示toast.xml的內容
TextView tv=(TextView)view.findViewById(R.id.tv1);
tv.setText("Toast顯示View內容");
//修改TextView裡的內容
toast.setDuration(Toast.LENGTH_SHORT);
//設定顯示時間,長時間Toast.LENGTH_LONG,短時間為Toast.LENGTH_SHORT,不可以自己編輯
toast.show();
}
下面是toast.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"
>
<ImageView android:src="@drawable/toast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView android:id="@+id/tv1"
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
android選擇對話方塊:
new AlertDialog.Builder(DialogDemo.this)
.setIcon(R.drawable.icon32)
.setTitle(R.string.alert_dialog_two_buttons_msg)
.setMessage(R.string.alert_dialog_two_buttons3_msg)
.setPositiveButton(R.string.alert_dialog_yes,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
/* User clicked OK so do some stuff */
}
})
.setNegativeButton(R.string.alert_dialog_no,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
/* User clicked OK so do some stuff */
}
})
.create();
setIcon使用表徵圖,setTitle()設定標題;setMessage()設定顯示對話方塊內容;setPositiveButton設定第一個按鈕,第一個屬性是設定按鈕內容,第二個屬性是設定點擊之後的事件;setNegativeButton設定第二個按鈕與第一個按鈕設定一樣。