我試圖創建一個警告對話框,頂部有一個圖像標題,底部有2個按鈕,我想從代碼中設置文本。但是我不能得到橫幅下的設置文本。我想創建類似於這個鏈接上的東西,但是文本總是在圖片上方結束,因爲我不知道如何引用對話框構建器中的textview。由於Android在警報對話框中設置文本
http://developer.android.com/guide/topics/ui/dialogs.html#CustomLayout
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater inflater = getLayoutInflater();
builder.setView(inflater.inflate(R.layout.custom_dialog, null))
.setMessage("Message" + message)
.setPositiveButton("Share", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if (isNetworkAvailable()){
if (......;
} else {
......
}
} else {
.......;
}
}
})
.setNegativeButton("Shake again!", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
}).setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
}
});
AlertDialog alert = builder.create();
alert.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
}
});
alert.show();
佈局XML文件是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:src="@drawable/yo3"
android:layout_width="match_parent"
android:layout_height="64dp"
android:scaleType="center"
android:background="#FFFFBB33"
android:contentDescription="@string/app_name" />
<TextView
android:id="@+id/dialogtext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>`
你爲什麼不加入佈局文件對話框文本? – Confuse 2014-10-21 04:10:20