设置视图时,Android警报对话框的空白

设置视图时,Android警报对话框的空白,第1张

概述我有个问题.我创建了一个警报对话框,其中显示了一条消息并带有“不再显示”复选框.当我在androidKK上运行此应用程序时,它显示正常,但是当我在androidjb上运行它时,它向我显示了此图像上的空白空间(当视图仅包含具有高度为0dp):http://foto.modelbouwforum.nl/images/2014/08/15/

我有个问题.我创建了一个警报对话框,其中显示了一条消息并带有“不再显示”复选框.当我在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                        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测试.

总结

以上是内存溢出为你收集整理的设置视图时,Android警报对话框的空白全部内容,希望文章能够帮你解决设置视图时,Android警报对话框的空白所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1077907.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存