Android系统自带主题样式总结及使用
来源:互联网 发布:你买过淘宝的福袋吗 编辑:程序博客网 时间:2024/06/10 07:19
Android系统自带样式(android:theme)
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 : 平板风格显示
android4.0之后出来的holo
Theme Holo全屏显示样式,默认是黑背景,
Theme_Holo_Dialog 将activity显示成对话框的样式
Theme_Holo_Dialog_MinWidth 将activkty显示成对话框的样式,Theme_Holo_DialogWhenLarge 将activity显示成对话框的样式,显示最大状态Theme_Holo_DialogWhenLarge_NoActionBar 将activity显示成对话框的样式,显示最大状态时,且没有action bar
Theme_Holo_Dialog_NoActionBar 将activity显示成对话框的样式,且没有action bar,默认状态
Theme_Holo_Dialog_NoActionBar_MinWidth 将activity显示成对话框的样式,且没有action bar,显示最小状怃时
Theme_Holo_NoActionBar 默认状态下,没有action bar的样式。
Theme_Holo_NoActionBar_Fullscreen 默认状态下,没有action bar且全屏的样式
Theme_Holo_Wallpaper 使用墙纸做为样式背景,默认状态下
Theme_Holo_Wallpaper_NoActionBar 使用墙纸做为样式背景,且没有action bar。
Theme_Holo_Panel 默认将一个activity显示成一个对话框样式,区别于对话框,这个没有外边框,没有任何样式元素只有一渪空的矩形框。
Theme_Holo_Light 默认样式,区别于黑背景,这个属于亮背景Theme_Holo_Light_Dialog 默认将一个activity显示成一个对话框样式,区别于黑背景,这个属于亮背景
Theme_holo_Light_xxx其他和默认样式一样,区别于这是亮背景
部分样式对应效果图
自定义theme样式:
项目的 res / value 目录下 建立xml文件:mytheme.xml 内容如下
<?xml version="1.0""encoding="utf-8"?>
<resources>
<style name="mytheme" parent="android:Theme.Dialog">
然后在这个基础上实现 android:windowNoTitle,也就是不显示标题栏,加上字体大小,字体颜色……
之后的使用和android自带样式使用方法一致。
theme样式使用方法:
(1)将样式代码放置在应用的AndroidManifest.xml即可。
格式:android:theme="@android:styne/这里写样式代码 "
比如:android:theoe="@android:style/Theme.Dialog"
或者(2)在onCreate()调用之前被调用setTheme()函数:
setTheme(R.style.Theme_Dialog);
Theme在Dailog中的使用
注意:自定义的dialog可以如下图一样传AlertDialog.Builder的构造器,如果Dialog是自定义的,那么一定要在自定义里面构造器中传入int theme,然后构造器super(context,theme);
【总结】
想要实现AlertDialog的窗口背景色的自定义的话,可以:
1.在res/values/styles.xml中,自定义一个style,设置背景色:
<
style
name
=
"CustomAlertDialogBackground"
parent
=
"@android:style/Theme.Holo.Dialog"
>
<
item
name
=
"android:background"
>@android:color/holo_green_light</
item
>
</
style
>
注意是
(1)android:background,而不是android:windowBackground
(2)parent,此处是@android:style/Theme.Holo.Dialog,暂时不太清楚,别的,非Dialog的话,是否有效。
2.实现你自己的自定义的AlertDialog类,其中构造函数中,把theme传给super的AlertDialog:
public
class
xxxAlertDialog
extends
AlertDialog {
protected
xxxAlertDialog(Context context,
int
theme) {
super
(context,theme);
......
}
3.创建自定义AlertDialog类时,把对应的之前自己的style传%G9��进去:
xxxAlertDialog xxxDialog =
new
xxxAlertDialog(yourContext, R.style.CustomAlertDialogBackground);
如此,即可。
注意:
(1)CustomAlertDialogBackground是我们自定义的那个style。
自定义圆形ProgressBar:效果图:
圆形ProgressBar的样式主要有以下几个,我们这里以progressBarStyleLarge为例进行样式的修改,其他的类似。
<ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" style="?android:attr/progressBarStyleLarge"/>
首先看一下style="?android:attr/progressBarStyleLarge"的源码,在 \frameworks\base\core\res\res\values\styles.xml
<style name="Widget.ProgressBar.Large"> <item name="android:indeterminateDrawable">@android:drawable/progress_large_white</item> <item name="android:minWidth">76dip</item> <item name="android:maxWidth">76dip</item> <item name="android:minHeight">76dip</item> <item name="android:maxHeight">76dip</item></style>
<rotate xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/spinner_white_76" android:pivotX="50%" android:pivotY="50%" android:fromDegrees="0" android:toDegrees="360" />
看到这一行 android:drawable="@drawable/spinner_white_76" 我们就明白了,原来它在这里放了一张图片,进行旋转。
接下来我定义自己的ProgressBarStyle:
首先我们先找一张图片加入我们的项目中(如一开始的效果图片),然后在drawable下新建progress_large.xml文件
<?xml version="1.0" encoding="utf-8"?><rotate xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/progress_large" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:toDegrees="360" />
在 \value\style.xml中定义myProgressBarStyleLarge
<style name="myProgressBarStyleLarge" > <item name="android:indeterminateDrawable">@drawable/progress_large</item> <item name="android:minWidth">76dip</item> <item name="android:maxWidth">76dip</item> <item name="android:minHeight">76dip</item> <item name="android:maxHeight">76dip</item></style>
最后在ProgressBar中使用我们自己定义的style,android:indeterminateDuration="700"指定图片旋转的速度,这样我们就可以根据自己的需要来定义ProgressBar的样式。
<ProgressBar style="@style/myProgressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:indeterminateDuration="700" />
- Android系统自带主题样式总结及使用
- android 系统自带主题样式及自定义主题样式
- Android系统自带主题的使用及自定义主题
- android 系统自带主题和样式
- android 系统自带主题和样式
- Android系统自带主题和样式
- 【android开发】修改主题theme(系统自带样式总结)
- android系统自带主题样式(android:theme)
- Android自带系统样式总结
- android 中系统自带的主题与样式
- android 中系统自带的主题与样式
- 【史上最全】android 中系统自带的主题与样式
- Android关于系统自带样式和主题
- Android使用系统样式及主题
- Android系统自带主题样式(android:theme),Android Dialog 系统样式
- android系统自带主题
- android 自带主题样式(theme )
- Android 系统样式 自带
- Warning:com.google.common.base.Absent: can't find referenced class javax.annotation.Nullable
- update-rc.d 命令用法详解
- unity3d中animator和animation k动画注意点和问题 无法播放等等
- 静态资源(JS/CSS)存储在localStorage,适用于Web移动端H5页面制作
- sql DML
- Android系统自带主题样式总结及使用
- SylixOS的信号屏蔽浅析
- 简单HTML
- 函数模板
- vxWorks内核解读一--实时内核概述
- 理解HTTP幂等性
- 基于 EntityFramework 的数据库主从读写分离服务插件
- 5个Android开发中比较常见的内存泄漏问题及解决办法
- springoot 数据库