這裏我我講一下android自定義對話框的開發。
這裏是效果圖
自定義界面很顯然我們需要一個佈局文件,在這個佈局文件中我們可以任意寫佈局代碼。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/dialog">
<TextView
android:id="@+id/text_dialog_todaymax"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dialog_texttips"
android:textSize="18sp"
/>
<EditText
android:id="@+id/dialog_edit_todaymax"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="@string/edit_values"
/>
</LinearLayout>
然後我們是java代碼,在你要彈出對話框的地方添加如下代碼:
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.today_dialog,
(ViewGroup) findViewById(R.id.dialog));
new AlertDialog.Builder(this).setTitle("每日流量").setView(layout)
.setPositiveButton("確定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).show();