android 對話方塊

來源:互聯網
上載者:User

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設定第二個按鈕與第一個按鈕設定一樣。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.