Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programatically set theme to android dialog box?

I am developing an application where in I have share and Rate options. When I click on these options I trigger an Intent which handles further proceedings. What I want is the dialog box these Intents open have some device default theme. So that different devices' dialog boxes will appear different. Also I have one dialog box for settings. How can I set the device default theme to this custom dialog that I have programatically? Thanks.

like image 583
user3686864 Avatar asked Jan 11 '23 00:01

user3686864


2 Answers

Craete a theme in style.xml and then you can pass the theme to dialog's constructor as:

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

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

like image 187
AndyN Avatar answered Jan 18 '23 17:01

AndyN


Define this theme in style.xml and set 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 will help.Thanks!

like image 41
Jagdish Avatar answered Jan 18 '23 17:01

Jagdish