应用样式的Andr​​oid [英] Applying Styles Android

查看:161
本文介绍了应用样式的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让我的活动看起来像一个对话框,但没有标题栏。所以我觉得我应该写这种风格我自己。

但这种XML风格应该如何?

我已经尝试过了Theme.Dialog我的活动,但事情是,我不希望Theme.Dialog风格的背景做。而如果没有对画面的标签。
我已经通过XML的所有屏幕的身材,我只想集中在屏幕上,并具有半透明的外底。


解决方案

只是这样做

 <活动机器人:名字=。MyActivity
机器人:主题=@风格/ CustomTheme
机器人:标签=加纳/>


  

RES /价值/ styles.xml


 <资源>
<样式名称=CustomTheme父=机器人:Theme.Dialog>
 <项目名称=机器人:windowNoTitle>真< /项目>
 <项目名称=机器人:layout_width>&WRAP_CONTENT LT; /项目>
 <项目名称=机器人:layout_height>&WRAP_CONTENT LT; /项目>
 <项目名称=机器人:背景> @绘制/ mybackground< /项目>
 <项目名称=安卓重力>中心< /项目>
 <项目名称=机器人:windowIsTranslucent>真< /项目>
 <项目名称=机器人:窗框> @空< /项目>
 <项目名称=机器人:windowBackground> @android:彩色/透明< /项目>
 <项目名称=机器人:windowIsFloating>真< /项目>
 <项目名称=机器人:windowContentOverlay> @空< /项目>
 <项目名称=机器人:windowAnimationStyle> @android:风格/ Animation.Dialog< /项目>
 <项目名称=机器人:backgroundDimEnabled>真< /项目>
 <项目名称=机器人:背景> @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.

解决方案

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.

这篇关于应用样式的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆