Search code examples
androiddialogthemesstyles

Applying Styles Android


I want to make my Activity appear like a Dialog box, but without the title bar. So I think I should write this style myself.

But how should this XML style be?

I already tried the Theme.Dialog for my Activity, but the thing is, I don't want the background of the Theme.Dialog style. And without an label for screen. I has all the screen build by XML, I want just center it on screen and has a semi-transparent outside background.


Solution

  • Just do this

    <activity android:name=".MyActivity" 
    android:theme="@style/CustomTheme" 
    android:label="Gana"/>
    

    res/values/styles.xml

    <resources>
    <style name="CustomTheme" parent="android:Theme.Dialog"> 
     <item name="android:windowNoTitle">true</item>
     <item name="android:layout_width">wrap_content</item>
     <item name="android:layout_height">wrap_content</item>
     <item name="android:background">@drawable/mybackground</item>
     <item name="android:gravity">center</item>
     <item name="android:windowIsTranslucent">true</item>
     <item name="android:windowFrame">@null</item>
     <item name="android:windowBackground">@android:color/transparent</item>
     <item name="android:windowIsFloating">true</item>
     <item name="android:windowContentOverlay">@null</item>
     <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
     <item name="android:backgroundDimEnabled">true</item>
     <item name="android:background">@android:color/transparent</item>
    
    </style>
       
    

    If you don't want background remove that.