这里我我讲一下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();