How to set theme programmatically in android dialog?

I am developing an application where I have share and Rate parameters. When I click on these options, I fire up an Intent that handles further actions. I want the dialog that these Intents open to have a default theme for the device. So the dialog boxes will differ from device to device. Also I have one dialog for settings. How can I customize the default device theme for this custom dialog that I have programmed? Thank.

+3


source to share


2 answers


Drag the theme into style.xml and then you can pass the theme to the dialog constructor like:

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



here TransparentTheme is the name of the theme I defined in style.xml

+5


source


Define this theme in your style.xml file and install it programmatically

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

      



I hope this helps. Thank!

+1


source







All Articles