Android自带的一些可用于Activity的Theme

http://kurtchen.com/blog/2010/03/10/android-theme/

在 AndroidMenifest.xml 中定义 Activity 的时候我们可以使用 android:theme 来设置 Activity 的主题,比如:

?
1
2
3
< activity android:name = ".MainActivity"
android:label = "@string/app_name"
android:theme = "@android:style/Theme.NoTitleBar" >

Android 本身自带了一些 Theme ,可以在frameworks/base/core/res/res/values/themes.xml中找到,从这个文件中也能看到默认的Theme是如何定义的(Theme)。

Theme
Theme.NoTitleBar
Theme.NoTitleBar.Fullscreen
Theme.Light
Theme.Light.NoTitleBar
Theme.Light.NoTitleBar.Fullscreen
Theme.Black
Theme.Black.NoTitleBar
Theme.Black.NoTitleBar.Fullscreen
Theme.Wallpaper
Theme.Wallpaper.NoTitleBar
Theme.Wallpaper.NoTitleBar.Fullscreen
Theme.WallpaperSettings
Theme.Light.WallpaperSettings
Theme.Translucent
Theme.Translucent.NoTitleBar
Theme.Translucent.NoTitleBar.Fullscreen
Theme.Dialog
Theme.Panel
Theme.Light.Panel
Theme.InputMethod

其中有一个比较有意思的是 Theme.NoDisplay :

Default theme for activities that don’t actually display a UI; that is, they finish themselves before being resumed.

还有几个不知道为什么是不能使用的(#TODO),比如 Theme.Dialog.Alert ,会报错:

Error: Resource is not public. (at ‘theme’ with value ‘@android:style/Theme.Dialog.Alert’)

当然,我们也可以自己创建Theme,比如:
colors.xml 
?
1
2
3
4
<? xml version = "1.0" encoding = "utf-8" ?>
< resources >
< drawable name = "green_background" >#ff00ff00</ drawable >
</ resources >

theme.xml

?
1
2
3
4
5
6
<? xml version = "1.0" encoding = "utf-8" ?>
< resources >
< style name = "MyTheme" >
< item name = "android:windowBackground" >@drawable/green_background</ item >
</ style >
</ resources >

Activity

?
1
2
3
< activity android:name = ".MainActivity"
android:label = "@string/app_name"
android:theme = "@style/MyTheme" >

再举个例子,比如在 theme.xml 中 Theme.Dialog.Alert 不给我们用,我们可以自己定义一份拿来使用:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
< style name = "MyDialog" >
< item name = "android:windowBackground" >@android:color/transparent</ item >
< item name = "android:windowTitleStyle" >@style/DialogWindowTitle</ item >
< item name = "android:windowIsFloating" >true</ item >
< item name = "android:windowContentOverlay" >@null</ item >
</ style >
< style name = "DialogWindowTitle" >
< item name = "android:maxLines" >1</ item >
< item name = "android:scrollHorizontally" >true</ item >
 
< item name = "android:textAppearance" >
@android:style/TextAppearance.DialogWindowTitle
</ item >
 
</ style >

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值