Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 自定义对话框大小匹配Theme.Holo.Light.Dialog大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如果我有一个活动,它的主题设置为Theme.Holo.Light.Dialog,它将扩大.它几乎完全以纵向模式在手机上填充屏幕,但在风景模式下,它不会拉长不合时宜.例如,在Google的这张照片中,您可以看到不填写整个屏幕的对话框.

它不会崩溃以匹配标题的宽度,如果您有通过扩展Dialog类的类拥有自己的Dialog构建将会发生什么.

这是我的布局会发生什么.

什么属性我需要应用于LinearLayout使它变得漂亮?

解决方法

您可以使用Theme.Holo.Light.Dialog.MinWidth来正确调整布局大小.

从文档:

使用它的方法是通过将ContextThemeWrapper代替到您的自定义Dialog的构造函数的Context(使用这个):

YourCustomDialog cDialog = new YourCustomDialog(
                        new ContextThemeWrapper(this,android.R.style.Theme_Holo_Light_Dialog_MinWidth));

这是如何定义Theme.Holo.Light.Dialog.MinWidth:

<style name="Theme.Holo.Light.Dialog.MinWidth">
    <item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
    <item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
</style>

来自dimensions.xml:

@android:扪/ dialog_min_width_major:

<!-- The platform's desired minimum size for a dialog's width when it
     is along the major axis (that is the screen is landscapE).  This may
     be either a fraction or a dimension. -->
<item type="dimen" name="dialog_min_width_major">65%</item>

@android:扪/ dialog_min_width_minor:

<!-- The platform's desired minimum size for a dialog's width when it
     is along the minor axis (that is the screen is porTrait).  This may
     be either a fraction or a dimension. -->
<item type="dimen" name="dialog_min_width_minor">95%</item>

看起来,您发布的图片中的对话框的宽度大约为65%.在肖像模式下,这将是95%.

老实说,在纵向模式下,宽度看起来不像95%,但是比以前更好:):

大佬总结

以上是大佬教程为你收集整理的android – 自定义对话框大小匹配Theme.Holo.Light.Dialog全部内容,希望文章能够帮你解决android – 自定义对话框大小匹配Theme.Holo.Light.Dialog所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。