如何以编程方式将主题设置为android对话框?

时间:2014-08-14 06:20:11

标签: android dialog android-theme

我正在开发一个应用程序,其中包含共享和速率选项。当我点击这些选项时,我会触发一个处理进一步程序的Intent。我想要的是这些Intents打开的对话框有一些设备默认主题。因此,不同的设备'对话框将显示不同。我还有一个设置对话框。如何将设备默认主题设置为此编程的自定义对话框? 感谢。

2 个答案:

答案 0 :(得分:6)

在style.xml中抓取主题,然后您可以将主题传递给对话框的构造函数:

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

此处 TransparentTheme 是我在style.xml中定义的主题的名称

答案 1 :(得分:1)

在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>

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

相关问题