您的位置:首页 > 移动开发 > Android开发

Android学习:不再提示对话框(创建自定义对话框)

2013-03-18 11:28 357 查看
界面:

创建自定义对话框首先应该定义对话框界面,我只是想要一个带有复选框的对话框界面,因此布局文件很简单:

<?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" >
<CheckBox
android:id="@+id/nomore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="不再提示" />
</LinearLayout>
接下来在应用程序中调用AlertDialog.Builder的setView(View view)方法让对话框显示该自定义界面即可。

final Builder builder=new AlertDialog.Builder(this);builder.setTitle("涉及系统权限,请您手动删除相应图片");
LinearLayout linearLayout=(LinearLayout)getLayoutInflater().inflate(R.layout.nomore, null);
builder.setView(linearLayout);
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
......
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
builder.create().show();
}
});




功能实现:将复选框的选择情况存储在SharedPreferences中,下次根据SharedPreferences中存储值判断是否弹出对话框。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: