Android主题和样式
1、位置
在Android的frameworks/base/core/res/res/values目录下有一下几个文件:
1
2
3
4
|
themes.xml
themes_device_defaults.xml
styles.xml
styles_device_defaults.xml
|
分别定义了各种系统Theme,Style。
2、主题Theme
主要关注themes.xml,themes_device_defaults.xml两个文件。
themes.xml定义了android低版本的theme和Holo theme,themes_device_defaults.xml定义了DeviceDefault主题(继承自Holo主题),实际上就是在Holo主题上定制主题(For厂商)。
系统如何去选择默认的主题呢?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
/**frameworks/base/core/java/android/content/res/Resources.java*/
/** @hide */
public static int selectDefaultTheme( int curTheme, int targetSdkVersion) {
return selectSystemTheme(curTheme, targetSdkVersion,
com.android.internal.R.style.Theme,
com.android.internal.R.style.Theme_Holo,
com.android.internal.R.style.Theme_DeviceDefault);
}
/** @hide */
public static int selectSystemTheme( int curTheme, int targetSdkVersion,
int orig, int holo, int deviceDefault) {
if (curTheme != 0 ) {
return curTheme;
}
if (targetSdkVersion < Build.VERSION_CODES.HONEYCOMB) {
// < 11
return orig;
}
if (targetSdkVersion < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
// < 14
return holo;
}
return deviceDefault;
}
|
当<11时,使用以前低版本主题;当>=11&&<14,使用Holo主题;>14的时候,使用DeviceDefault主题。
方便理解,下面把目前所有的版本号列出来,也顺便温习一下android的历史:
3、系统主题Theme列表
系统默认大的主题是三种:Theme,Theme.Holo,Theme.DeviceDefault, 但是实际上在此基础系统还定义了大量的派生主题,最典型的是对应的Light主题。
除此之外,还有很多,在此一一列出,打字太痛苦了,我贴出截图:
了解android系统定义的主题之后,我们就可以根据实际情况在自己的应用中使用这些主题,但是如果想修改主题的某些内容,需要进一步深入。
4、详解每个主题中定义item分类
一个完整的主题应该定义哪些内容呢,以Theme为例,如下:
1)颜色
1
2
3
4
5
6
7
8
9
10
|
<item name= "colorForeground" > @android :color/bright_foreground_dark</item>
<item name= "colorForegroundInverse" > @android :color/bright_foreground_dark_inverse</item>
<item name= "colorBackground" > @android :color/background_dark</item>
<item name= "colorBackgroundCacheHint" >?android:attr/colorBackground</item>
<item name= "colorPressedHighlight" > @color /legacy_pressed_highlight</item>
<item name= "colorLongPressedHighlight" > @color /legacy_long_pressed_highlight</item>
<item name= "colorFocusedHighlight" > @color /legacy_selected_highlight</item>
<item name= "colorMultiSelectHighlight" > @color /legacy_selected_highlight</item>
<item name= "colorActivatedHighlight" > @color /legacy_selected_highlight</item>
|
2)字体
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
<!-- Text styles -->
<item name= "textAppearance" > @android :style/TextAppearance</item>
<item name= "textAppearanceInverse" > @android :style/TextAppearance.Inverse</item>
<item name= "textColorPrimary" > @android :color/primary_text_dark</item>
<item name= "textColorSecondary" > @android :color/secondary_text_dark</item>
<item name= "textColorTertiary" > @android :color/tertiary_text_dark</item>
<item name= "textColorPrimaryInverse" > @android :color/primary_text_light</item>
<item name= "textColorSecondaryInverse" > @android :color/secondary_text_light</item>
<item name= "textColorTertiaryInverse" > @android :color/tertiary_text_light</item>
<item name= "textColorPrimaryDisableOnly" > @android :color/primary_text_dark_disable_only</item>
<item name= "textColorPrimaryInverseDisableOnly" > @android :color/primary_text_light_disable_only</item>
<item name= "textColorPrimaryNoDisable" > @android :color/primary_text_dark_nodisable</item>
<item name= "textColorSecondaryNoDisable" > @android :color/secondary_text_dark_nodisable</item>
<item name= "textColorPrimaryInverseNoDisable" > @android :color/primary_text_light_nodisable</item>
<item name= "textColorSecondaryInverseNoDisable" > @android :color/secondary_text_light_nodisable</item>
<item name= "textColorHint" > @android :color/hint_foreground_dark</item>
<item name= "textColorHintInverse" > @android :color/hint_foreground_light</item>
<item name= "textColorSearchUrl" > @android :color/search_url_text</item>
<item name= "textColorHighlight" > @android :color/highlighted_text_dark</item>
<item name= "textColorHighlightInverse" > @android :color/highlighted_text_light</item>
<item name= "textColorLink" > @android :color/link_text_dark</item>
<item name= "textColorLinkInverse" > @android :color/link_text_light</item>
<item name= "textColorAlertDialogListItem" > @android :color/primary_text_light_disable_only</item>
<item name= "textAppearanceLarge" > @android :style/TextAppearance.Large</item>
<item name= "textAppearanceMedium" > @android :style/TextAppearance.Medium</item>
<item name= "textAppearanceSmall" > @android :style/TextAppearance.Small</item>
<item name= "textAppearanceLargeInverse" > @android :style/TextAppearance.Large.Inverse</item>
<item name= "textAppearanceMediumInverse" > @android :style/TextAppearance.Medium.Inverse</item>
<item name= "textAppearanceSmallInverse" > @android :style/TextAppearance.Small.Inverse</item>
<item name= "textAppearanceSearchResultTitle" > @android :style/TextAppearance.SearchResult.Title</item>
<item name= "textAppearanceSearchResultSubtitle" > @android :style/TextAppearance.SearchResult.Subtitle</item>
<item name= "textAppearanceEasyCorrectSuggestion" > @android :style/TextAppearance.EasyCorrectSuggestion</item>
<item name= "textAppearanceMisspelledSuggestion" > @android :style/TextAppearance.MisspelledSuggestion</item>
<item name= "textAppearanceAutoCorrectionSuggestion" > @android :style/TextAppearance.AutoCorrectionSuggestion</item>
<item name= "textAppearanceButton" > @android :style/TextAppearance.Widget.Button</item>
<item name= "editTextColor" > @android :color/primary_text_light</item>
<item name= "editTextBackground" > @android :drawable/edit_text</item>
<item name= "candidatesTextStyleSpans" > @android :string/candidates_style</item>
<item name= "textCheckMark" > @android :drawable/indicator_check_mark_dark</item>
<item name= "textCheckMarkInverse" > @android :drawable/indicator_check_mark_light</item>
<item name= "textAppearanceLargePopupMenu" > @android :style/TextAppearance.Widget.PopupMenu.Large</item>
<item name= "textAppearanceSmallPopupMenu" > @android :style/TextAppearance.Widget.PopupMenu.Small</item>
|
3)按钮
1
2
3
4
5
6
7
8
9
10
11
|
<!-- Button styles -->
<item name= "buttonStyle" > @android :style/Widget.Button</item>
<item name= "buttonStyleSmall" > @android :style/Widget.Button.Small</item>
<item name= "buttonStyleInset" > @android :style/Widget.Button.Inset</item>
<item name= "buttonStyleToggle" > @android :style/Widget.Button.Toggle</item>
<item name= "selectableItemBackground" > @android :drawable/item_background</item>
<item name= "borderlessButtonStyle" >?android:attr/buttonStyle</item>
<item name= "homeAsUpIndicator" > @android :drawable/ic_ab_back_holo_dark</item>
|
4)List
1
2
3
4
5
6
7
8
9
10
11
|
<!-- List attributes -->
<item name= "listPreferredItemHeight" >64dip</item>
<item name= "listPreferredItemHeightSmall" >?android:attr/listPreferredItemHeight</item>
<item name= "listPreferredItemHeightLarge" >?android:attr/listPreferredItemHeight</item>
<item name= "dropdownListPreferredItemHeight" >?android:attr/listPreferredItemHeight</item>
<item name= "textAppearanceListItem" >?android:attr/textAppearanceLarge</item>
<item name= "textAppearanceListItemSmall" >?android:attr/textAppearanceLarge</item>
<item name= "listPreferredItemPaddingLeft" >6dip</item>
<item name= "listPreferredItemPaddingRight" >6dip</item>
<item name= "listPreferredItemPaddingStart" >6dip</item>
<item name= "listPreferredItemPaddingEnd" >6dip</item>
|
5)Window
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<!-- Window attributes -->
<item name= "windowBackground" > @android :drawable/screen_background_selector_dark</item>
<item name= "windowFrame" > @null </item>
<item name= "windowNoTitle" > false </item>
<item name= "windowFullscreen" > false </item>
<item name= "windowOverscan" > false </item>
<item name= "windowIsFloating" > false </item>
<item name= "windowContentOverlay" > @null </item>
<item name= "windowShowWallpaper" > false </item>
<item name= "windowTitleStyle" > @android :style/WindowTitle</item>
<item name= "windowTitleSize" >25dip</item>
<item name= "windowTitleBackgroundStyle" > @android :style/WindowTitleBackground</item>
<item name= "android:windowAnimationStyle" > @android :style/Animation.Activity</item>
<item name= "android:windowSoftInputMode" >stateUnspecified|adjustUnspecified</item>
<item name= "windowActionBar" > false </item>
<item name= "windowActionModeOverlay" > false </item>
<item name= "windowCloseOnTouchOutside" > false </item>
<item name= "windowTranslucentStatus" > false </item>
<item name= "windowTranslucentNavigation" > false </item>
|
6)Dialog
1
2
3
4
5
|
<!-- Dialog attributes -->
<item name= "dialogTheme" > @android :style/Theme.Dialog</item>
<item name= "dialogTitleIconsDecorLayout" > @layout /dialog_title_icons</item>
<item name= "dialogCustomTitleDecorLayout" > @layout /dialog_custom_title</item>
<item name= "dialogTitleDecorLayout" > @layout /dialog_title</item>
|
7)AlertDialog
1
2
3
4
5
|
<!-- AlertDialog attributes -->
<item name= "alertDialogTheme" > @android :style/Theme.Dialog.Alert</item>
<item name= "alertDialogStyle" > @android :style/AlertDialog</item>
<item name= "alertDialogCenterButtons" > true </item>
<item name= "alertDialogIcon" > @android :drawable/ic_dialog_alert</item>
|
8)Panel
1
2
3
4
5
6
7
8
9
10
|
<!-- Panel attributes -->
<item name= "panelBackground" > @android :drawable/menu_background</item>
<item name= "panelFullBackground" > @android :drawable/menu_background_fill_parent_width</item>
<!-- These three attributes do not seems to be used by the framework. Declared public though -->
<item name= "panelColorBackground" ># 000 </item>
<item name= "panelColorForeground" >?android:attr/textColorPrimary</item>
<item name= "panelTextAppearance" >?android:attr/textAppearance</item>
<item name= "panelMenuIsCompact" > false </item>
<item name= "panelMenuListWidth" >296dip</item>
|
9)滚动条(Scrollbar)
1
2
3
4
5
6
7
8
|
<!-- Scrollbar attributes -->
<item name= "scrollbarFadeDuration" > 250 </item>
<item name= "scrollbarDefaultDelayBeforeFade" > 300 </item>
<item name= "scrollbarSize" >10dip</item>
<item name= "scrollbarThumbHorizontal" > @android :drawable/scrollbar_handle_horizontal</item>
<item name= "scrollbarThumbVertical" > @android :drawable/scrollbar_handle_vertical</item>
<item name= "scrollbarTrackHorizontal" > @null </item>
<item name= "scrollbarTrackVertical" > @null </item>
|
10)文字选中(Text selection)
1
2
3
4
5
6
7
8
9
10
11
12
|
<!-- Text selection handle attributes -->
<item name= "textSelectHandleLeft" > @android :drawable/text_select_handle_left</item>
<item name= "textSelectHandleRight" > @android :drawable/text_select_handle_right</item>
<item name= "textSelectHandle" > @android :drawable/text_select_handle_middle</item>
<item name= "textSelectHandleWindowStyle" > @android :style/Widget.TextSelectHandle</item>
<item name= "textEditPasteWindowLayout" > @android :layout/text_edit_paste_window</item>
<item name= "textEditNoPasteWindowLayout" > @android :layout/text_edit_no_paste_window</item>
<item name= "textEditSidePasteWindowLayout" > @android :layout/text_edit_side_paste_window</item>
<item name= "textEditSideNoPasteWindowLayout" > @android :layout/text_edit_side_no_paste_window</item>
<item name= "textSuggestionsWindowStyle" > @android :style/Widget.TextSuggestionsPopupWindow</item>
<item name= "textEditSuggestionItemLayout" > @android :layout/text_edit_suggestion_item</item>
<item name= "textCursorDrawable" > @null </item>
原文链接
http://www.cnblogs.com/qianxudetianxia/p/3725466.html
|
Android主题和样式相关推荐
- Android主题和样式之系统篇(上)
[基于最新的Android4.4的源码分析] 每家公司或者每个移动团队无不想开发出一套自己的UI框架,融入自己的设计和特性,这必然会去修改android的ui. 所以,学习和理解android的UI设 ...
- Android主题与样式
一.样式 样式是属性的集合,例如定义属性fontColor.fontSize.layout_width.layout_height等,以独立的资源文件存放在XML文件中,并设置样式的名称. Andro ...
- Android 主题Theme样式一键换肤,非常简单(附小案例)
导语 谷歌v7后的主题Theme其实就有意给开发者们开辟换肤的功能,我们一起手动制作一款可以换肤主题,开始撸码吧! 一.统一自定义属性名 attr.xml <?xml version=" ...
- AndroidStudio安卓原生开发_UI高级_自定义主题和样式---Android原生开发工作笔记129
然后我们再来看android中的主题和样式,首先我们去看主题, 主题就是我们看到的一个app的整体样式.但是他可以设置给某个activity,所以也可以具体点说, 他是activity窗体级别的. 而 ...
- android中的样式和主题
有的时候我们一个页面要用很多个textview,而且这些textview的样式非常相像,这种情况下我们可以把这些样式抽取出来,然后在每个textview中引用即可,这样修改起来也方便. 我们来看一个简 ...
- android中样式文件步骤,详解Android主题开发的样式教程
Android中的样式和css样式作用相似,都是用于为界面元素定义显示风格,它是一个包含一个或者多个view 控件属性的集合.主题是一个包含一种或者多种格式化属性的集合,你可以将其为一个单位用在应用中 ...
- Android主题样式style背景色(图片),在刘海屏上出现黑条问题
Android主题样式style背景色(图片),在刘海屏上出现黑条问题 一般Launcher页会设置一个主题样式,配置一个背景图片来解决Activity的xml布局未显示时的一小段白屏或黑屏的时间,然 ...
- Android系统自带主题样式(android:theme),Android Dialog 系统样式
部分转载:http://stephen830.iteye.com/blog/1129203 , http://blog.sina.com.cn/s/blog_3e333c4a0102vk0f.htm ...
- Android:主题(Theme)
1.主题和样式的区别主要区别在 主题不能作用于单个View组建,主题应该对整个应用中的所有Activity起作用或者对指定的Activity起作用. 主题定义的格式应该是改变窗口的外观格式,例如窗口变 ...
- Android 主题设计全解析
Android主题设计!有点乱? 初学Android的时候对Android的主题设计都是处在一种模糊的认知状态,为啥呢? 自定义时候的attr,普通view的style属性,activity以及app ...
最新文章
- 序列化:ProtoBuf与JSON的比较
- Hadoop之Storm命令
- 想做测试经理的看过来
- what is your research about?
- 后台服务系统之什么是dubbo
- Vivado中RTL封装IP流程
- mysql触发器可以使用正则表达式,是否可以使用正则表达式在MySQL中强制执行数据检查...
- 使用网络调试助手 MQTT接入阿里云物联网平台,逐字节讲解,适用单片机/ESP8266接入阿里云
- 连续年份高精度人口密度分布数据
- 推荐育儿书《正面管教》
- 计算机工程中级职称怎么考,以前中级职称是要考什么计算机-计算机软考中级职称哪个好考...
- Codeforces_714_A
- python基础语法及知识点总结
- poll?transport=longpollconnection...烦人的请求
- 2022年东北大学计算机考研复试最低分数线
- 2019年北京移动电信联通校园卡200打一年300打两年套餐对比
- 第七次霍乱大流行致病弧菌的两个防御系统
- 游戏画面的印象判断价值和审美属性分析
- Bios设置引起linux卡界面,根据显示的BIOS信息来处理电脑无法启动故障的方法
- iOS进阶--蓝牙技术
热门文章
- 电脑重复文件扫描工具清理:Easy duplicate finder 5.10注册破解版
- 关于百度机器人搜索你网站的页面权限设置
- Day001-2021-07-29 变量定义/数据类型/基础运算 判断/循环/数组
- 零售商店销售管理系统——第四周
- 学习Vue3 第七章(认识Reactive全家桶)
- %1 不是有效的 Win32 应用程序。
- css html5布局方式_创建新HTML5 / CSS3单页布局–艺术主题
- 活动|域名转入专场活动
- lvm卷的缩减和扩容
- 2021年安全生产模拟考试(全国特种作业操作证电工作业-继电保护模拟考试题库一)安考星