【问题标题】:Change the style of AlertDialog更改 AlertDialog 的样式
【发布时间】:2011-11-04 15:41:32
【问题描述】:

当我运行此代码时,会显示警报对话框,但对话框周围有一个白色边框,而且边框有点圆。我不想要这个白色边框,我想要真正的角为 90 度的角。我希望你明白我想要做什么。

        AlertDialog.Builder ad = new AlertDialog.Builder(this);
        Button bbb=new Button(MvcnContactList.this);
        ad.setView(bbb);
        alertDialog = ad.create();
        alertDialog.show();

是否有任何方法可以设置警报对话框的样式,但不能设置文本颜色或文本大小或类似的样式...我想设置警报对话框的边框样式,因此仅设置一个主题也许可以解决此问题。但我不知道要覆盖哪些属性。

谢谢,

编辑: 例如,这种样式将 textColor 覆盖为 00FF00 ,这很酷,但是我应该覆盖哪个属性以使角不圆并移除那个白色的钻孔

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AlertDialogCustom" parent="@android:style/AlertDialog">
        <item name="android:textColor">#00FF00</item>
        <item name="android:typeface">monospace</item>
        <item name="android:textSize">10sp</item>
    </style>
</resources>

【问题讨论】:

标签: android coding-style dialog themes android-gui


【解决方案1】:

我找到了包装器的解决方案,您可以在其中为当前上下文中的任何内容设置主题(样式)。我将 R.style.MyTheme 设置为警报对话框的样式,并根据自己的喜好定制了该视图。

ContextThemeWrapper ctw = new ContextThemeWrapper( this, R.style.MyTheme );
        AlertDialog.Builder builder= new AlertDialog.Builder( ctw );

【讨论】:

  • 但是您在主题中覆盖了哪些属性以删除圆角和边框?我有同样的问题..
  • 能否请您解释/提供一个代码示例来说明您是如何移除白色边框的?
【解决方案2】:

你自己回答了你的问题,但它对我没有用,所以这里是我的回答希望对每个需要它的人有所帮助:

<style name="PauseDialog" parent="@android:style/Theme.Dialog">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>

</style>

将此样式放在 res\values\styles.xml 文件中,然后在 Manifest 中将活动的主题设置为它。像这样:

android:theme="@style/PauseDialog" 

【讨论】:

    猜你喜欢
    • 2021-01-19
    • 2015-12-22
    • 1970-01-01
    • 2013-04-18
    • 2016-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-09
    相关资源
    最近更新 更多