我有个问题.我创建了一个警报对话框,其中显示了一条消息并带有“不再显示”复选框.当我在android KK上运行此应用程序时,它显示正常,但是当我在android jb上运行它时,它向我显示了此图像上的空白空间(当视图仅包含具有高度为0dp):
http://foto.modelbouwforum.nl/images/2014/08/15/Screenshot2014-08-15-14-33-40.png
我的警报对话框代码:
final SharedPreferences sharedPreferences=getSharedPreferences("appPrefs", Context.MODE_PRIVATE);
if(!sharedPreferences.getBoolean("isTutorialMainScreenChecked", false)){
View checkBoxView = View.inflate(MainScreenHandler.this, R.layout.checkbox_alert_dialog,null);
checkBox = (CheckBox) checkBoxView.findViewById(R.id.checkbox);
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setMessage(getString(R.string.alertDialog_main_screen_tutorial));
builder.setCancelable(false);
builder.setView(checkBoxView);
builder.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if(checkBox.isChecked()){
SharedPreferences.Editor editor=sharedPreferences.edit();
editor.putBoolean("isTutorialMainScreenChecked", true);
editor.commit();
}
dialogInterface.dismiss();
}
});
builder.setNegativeButton(getString(R.string.alertDialog_cancel),
new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialogInterface, int i){
dialogInterface.cancel();
}
});
alertDialog = builder.create();
alertDialog.show();
这是我的复选框布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:baselineAligned="false">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#ffff3bb2"/>
<CheckBox
style="@android:style/TextAppearance.Small"
android:textColor="#ff000000"
android:text="@string/alertDialog_checkbox_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/checkbox"/>
</LinearLayout>
提前致谢
邮编:
这是在android KK上的样子:
http://foto.modelbouwforum.nl/images/2014/08/15/QuickMemo2014-08-15-14-42-41.png
解决方法:
我查看了API 19中alert_dialog.xml布局的来源,发现以下用于插入自定义视图的布局:
<FrameLayout android:id="@+id/customPanel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<FrameLayout android:id="@+android:id/custom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dip"
android:paddingBottom="5dip" />
</FrameLayout>
然后,我尝试设置背景以查看哪个视图占用了空间. customPanel被涂成红色,自定义视图被涂成绿色.
AlertDialog d = builder.create();
d.show();
View v = (View)d.getWindow().findViewById(android.R.id.custom).getParent();
v.setBackgroundColor(Color.RED);
这张图片意味着customPanel应该有一些填充,或者custom应该有非零的布局参数或其他.在检查了那些等于零的属性之后,我尝试测试customPanel的minimumHeight,并在xxhdpi或64dp上获得192.此设置导致框架大于嵌套的自定义视图.
我还没有弄清楚在哪里应用此设置,但这是解决方法:
AlertDialog d = builder.create();
d.show();
View v = (View)d.getWindow().findViewById(android.R.id.custom).getParent();
v.setMinimumHeight(0);
经过API 18,19测试.
标签:alertdialog,android 来源: https://codeday.me/bug/20191121/2051285.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。