AlertDialog 中的复选框被“推出”通过文本视图
我正在尝试创建一个 AlertDialog 以在我的应用程序中显示介绍消息,其下方有一个“不再显示此消息”复选框。
当 AlertDialog 的消息很短时,它效果很好,但是当太长(需要滚动)时,复选框将不再显示。它被 TextView“推出”。
自定义视图的 XML (dont_show_again.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Don't show this again">
</CheckBox>
</LinearLayout>
以及显示 AlertDialog 的代码
String longMessage = getString(R.string.long_message);
LayoutInflater inflater = getLayoutInflater();
final View checkboxLayout = inflater.inflate(R.layout.dont_show_again, null);
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setTitle("Some message")
.setMessage(longMessage)
.setView(checkboxLayout)
.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog dialog = builder.create();
dialog.show();
关于如何解决这个问题有什么想法吗?也许有人有一个工作警报对话框的示例,其中带有“不再显示此”复选框?
I'm trying to create an AlertDialog to show an introduction message in my application, with a "Don't show this again" CheckBox below it.
It works well when the message of the AlertDialog is short, but when is too long (requiring scrolling) the CheckBox is no longer shown. It gets "pushed out" by the TextView.
The XML for the custom view (dont_show_again.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Don't show this again">
</CheckBox>
</LinearLayout>
And the code to display the AlertDialog
String longMessage = getString(R.string.long_message);
LayoutInflater inflater = getLayoutInflater();
final View checkboxLayout = inflater.inflate(R.layout.dont_show_again, null);
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setTitle("Some message")
.setMessage(longMessage)
.setView(checkboxLayout)
.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog dialog = builder.create();
dialog.show();
Any ideas on how to solve this? Perhaps someone has an example of a working AlertDialog with a "Don't show this again" CheckBox?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要设置对话框消息,而是将其作为 textView 包含在布局 XML 中。
Don't set the dialog box message, instead include it in the layout XML as textView.
使用前面答案中的 XML 布局。
Use the XML layout from the answer earlier.