Android系统自带主题的使用及自定义主题
系统自带主题
将样式代码放置在应用的AndroidManifest.xml的activity中,代码格式为:
android:theme="@android:style/Theme.Dialog"
或者在onCreate()
中setContentView()
之前调用setTheme()
函数:
setTheme(R.style.Theme_Dialog);
Theme.Dialog
: Activity显示为对话框模式
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.Translucent
: 透明背景
Theme.Translucent.NoTitleBar
: 透明背景并无标题
Theme.Translucent.NoTitleBar.Fullscreen
: 透明背景并无标题,全屏
Theme.Panel
: 面板风格显示
Theme.Light.Panel
: 平板风格显示
自定义主题
项目的 res / value 目录下建立xml文件:mytheme.xml 内容如下
<?xml version="1.0" encoding="utf-8"?><resources><style name="mytheme" parent="android:Theme.Dialog"> <item name="android:windowNoTitle">true</item> <item name="android:textSize">20sp</item> <item name="android:textColor">#000000</item> </style></resources>
注:
parent 属性用来继承,我们这个主题就继承自android提供的Dialog主题
然后在这个基础上实现 android:windowNoTitle,也就是不显示标题栏,加上字体大小,字体颜色……
在 AndroidManifest.xml 里使用你创建的主题:
<activity android:name=".MainActivity" android:theme="@style/mytheme"/>
或者在onCreate()
中setContentView()
之前调用setTheme()
函数:
setTheme(R.style.mytheme);
转载自:http://blog.sina.com.cn/s/blog_627ebfc3010119ih.html
更多相关文章
- Android中主题的添加
- Android应用程序的权限列表
- [入门]Android的应用程序框架
- Android应用程序剖析
- android shape设置背景风格为圆角
- Android边框背景
- 最全的PHP开发Android应用程序