Applying Styles Android

三世轮回 提交于 2019-12-10 11:21:53

问题


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.


回答1:


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>

try this. this will work well .

if you dont want background remove that.


Thanks.



来源:https://stackoverflow.com/questions/5473822/applying-styles-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!