【问题标题】:How to programatically set theme to android dialog box?如何以编程方式将主题设置为 android 对话框?
【发布时间】:2014-08-14 06:20:11
【问题描述】:

我正在开发一个应用程序,其中有分享和评分选项。当我点击这些选项时,我会触发一个 Intent 来处理进一步的程序。我想要的是这些 Intents 打开的对话框有一些设备默认主题。使不同设备的对话框出现不同。我还有一个设置对话框。如何将设备默认主题设置为我以编程方式拥有的自定义对话框? 谢谢。

【问题讨论】:

    标签: android dialog android-theme


    【解决方案1】:

    在 style.xml 中创建一个主题,然后你可以将主题传递给对话框的构造函数:

    Dialog d = new Dialog(getApplicationContext(), R.style.TransparentTheme);

    这里 TransparentTheme 是我在 style.xml 中定义的主题名称

    【讨论】:

    • 您好,感谢您的回复,但我不想在任何地方定义主题,只需使用设备默认主题即可。
    • 如果您没有为自定义对话框传递任何主题,它将采用设备的默认主题。
    【解决方案2】:

    在 style.xml 中定义这个主题并以编程方式设置它

    <style name="DialogTheme" parent="android:Theme.Dialog">
            <item name="android:layout_width">fill_parent</item>
            <item name="android:layout_height">fill_parent</item>
    
            <!-- No backgrounds, titles or window float -->
            <item name="android:windowNoTitle">false</item>
            <item name="android:windowFullscreen">true</item>
            <item name="android:windowIsFloating">false</item>
     </style>
    

    我希望这会有所帮助。谢谢!

    【讨论】:

      猜你喜欢
      • 2011-06-25
      • 2016-06-20
      • 2015-01-14
      • 2011-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-15
      相关资源
      最近更新 更多