android 用自定义样式设计界面,Android Style开发之Theme

1概述

Theme是针对窗体设计的,用以改变窗体样式;Style是针对窗体元素的,用以改变指定控件或layout的样式。

Android系统的themes.xml和style.xml文件位于frameworks/base/core/res/res/values中。里面涉及到很多.9.png文件,路径位于frameworks/base/core/res/res/drawable-hdpi

2 系统主题分类

themes.xml //API10以前

themes_hole.xml //APi 11

themes_device_defaults.xml //API14

themes_material.xml //API21

themes_micro.xml //Android Wear

themes_leanback.xml //not know

兼容包AppCompat

2.1 androidManifest.xml中设置

android:icon="@mipmap/ic_launcher"

android:theme="@style/AppTheme.NoActionBar">

android:name=".MainActivity"

android:theme="@style/Base.TextAppearance.AppCompat">

2.2 java设置

setTheme(theme); //这里必须在super方法之前调用,不然不能生效!

super.onCeate(saveInstance)

2.3 常用theme列表

android:theme="@android:style/Theme.Dialog" 将一个Activity显示为对话框模式

•android:theme="@android:style/Theme.NoTitleBar" 不显示应用程序标题栏

•android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 不显示应用程序标题栏,并全屏

•android:theme="@android:style/Theme.Light" 背景为白色

•android:theme="@android:style/Theme.Light.NoTitleBar" 白色背景并无标题栏

•android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" 白色背景,无标题栏,全屏

•android:theme="@android:style/Theme.Black" 背景黑色

•android:theme="@android:style/Theme.Black.NoTitleBar" 黑色背景并无标题栏

•android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" 黑色背景,无标题栏,全屏

•android:theme="@android:style/Theme.Wallpaper" 用系统桌面为应用程序背景

•android:theme="@android:style/Theme.Wallpaper.NoTitleBar" 用系统桌面为应用程序背景,且无标题栏

•android:theme="@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen" 用系统桌面为应用程序背景,无标题栏,全屏

•android:theme="@android:style/Translucent" 半透明效果

•android:theme="@android:style/Theme.Translucent.NoTitleBar" 半透明并无标题栏

•android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" 半透明效果,无标题栏,全屏

•android:theme="@android:style/Theme.Panel"

2.4 ProgressBar

style="?android:attr/progressBarStyleHorizontal"

style="?android:attr/progressBarStyleLarge"

style="?android:attr/progressBarStyleSmall"

style="?android:attr/progressBarStyleSmallTitle"

2.5 CheckBox样式

style="?android:attr/starStyle" 星形

2.6 类似标题栏效果的TextView

style="?android:attr/listSeparatorTextViewStyle"

2.7 其它有用的样式

android:layout_height="?android:attr/listPreferredItemHeight"

android:paddingRight="?android:attr/scrollbarSize"

style="?android:attr/windowTitleBackgroundStyle"

style="?android:attr/windowTitleStyle"

android:layout_height="?android:attr/windowTitleSize"

android:background="?android:attr/windowBackground"

3 字体

3.1 Android平台定义了三种字体大小:

"?android:attr/textAppearanceLarge"

"?android:attr/textAppearanceMedium"

"?android:attr/textAppearanceSmall"

3.2 Android字体颜色:

android:textColor="?android:attr/textColorPrimary"

android:textColor="?android:attr/textColorSecondary"

android:textColor="?android:attr/textColorTertiary"

android:textColor="?android:attr/textColorPrimaryInverse"

android:textColor="?android:attr/textColorSecondaryInverse"

4 分隔符

4.1 横向:

android:layout_width="fill_parent"

android:layout_height="1dip"

android:background="?android:attr/listDivider" />

4.2 纵向:

android:layout_height="fill_parent"

android:background="?android:attr/listDivider" />

4.3 space

space是Android 4.0中新增的一个控件,它实际上可以用来分隔不同的控件,其中形成一个空白的区域,它通过android:layout_row及android:layout_column指定了其起始位置。

5 修改Activity的标题栏样式

5.1 在styles.xml中增加一个自定义style

例如

5.2 再修改AndroidManifest.xml文件,找到要自定义标题栏的Activity,添加上android:theme值。

比如:

5.3 去掉所有Activity界面的标题栏

修改AndroidManifest.xml

在application 标签中添加android:theme=”@android:style/Theme.NoTitleBar”

6 Material Theme

6.1 material主题

@android:style/Theme.Material //黑色背景

@android:style/Theme.Material.Light //白色背景

@android:style/Theme.Material.Light.DarkActionBar //白色背景黑色titlebar

6.2 自定义颜色基调

自定义主题的基础色调如下:

6.3 自定义颜色

colorPrimary ActionBar导航栏颜色;ToolBar使用toolBar的属性background设置导航栏背景颜色

colorPrimaryDark 系统状态栏颜色

textColorPrimary 导航栏字体颜色

windowBackground 主界面背景色

navigationBarColor 底部系统导航栏颜色(api21加才有)

colorControlHighlight 波纹颜色(Ripple)

colorAccent 控件的选中颜色(如checkbox/radiobutton等选中状态)

如图所示

6.4 Elevation

android 5.0增加了z轴,其中使用android:elevation来设置阴影的大小和绘制顺序。transitionZ属性可以实现临时变更elevation的动画,一般用于触摸反馈。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值