山西网站群建设,如何制作wordpress主题,怎么建立自己的网页,python开发app原文地址 : http://android.xsoftlab.net/training/basics/actionbar/styling.html
ActionBar的样式
ActionBar提供了为用户提供了常见的习惯性的用户界面以及按钮功能。但是这并不意味着必须要和其它APP看起来一模一样。如果需要设计更符合产品品牌样式风格的话#xff0c;…原文地址 : http://android.xsoftlab.net/training/basics/actionbar/styling.html
ActionBar的样式
ActionBar提供了为用户提供了常见的习惯性的用户界面以及按钮功能。但是这并不意味着必须要和其它APP看起来一模一样。如果需要设计更符合产品品牌样式风格的话ActionBar也可以做到你可以通过Android的style and theme很容易做到这一点。
Android已经包含了一少部分的内置Activity主题这些主题包含了”dark”或者”light”的ActionBar风格。你也可以通过继承这些主题来进一步的自定义自己ActionBar。 Note如果使用的是ActionBar的支持库那么你必须使用Theme.AppCompat 家族的风格。在这样的情况下每一个样式属性必须声明两次一次是在平台样式属性中一次是在支持库样式属性中。相关情况请看下面的样例。 使用一个Android主题 Android内置了两种最基本的Activity主题它们区别在于ActionBar的颜色
Theme.Holo 是”dark”主题。Theme.Holo.Light 是”light”主题。
你可以将这些主题应用到整个APP中或者是单个Activity中通过在清单文件的 application元素或是 activity元素内部使用android:theme属性来指定
application android:themeandroid:style/Theme.Holo.Light ... / 你也可以通过使用Theme.Holo.Light.DarkActionBar主题来达到ActionBar是”dark”样式而Activity的其余部分则是”light”样式的效果。
如果是使用了支持库的话必须使用Theme.AppCompat下的主题
Theme.AppCompat 对应的是”dark”主题.Theme.AppCompat.Light 对应的是”light”主题.Theme.AppCompat.Light.DarkActionBar 对应的是带着黑色ActionBar的亮色主题.
请确保在ActionBar上图标颜色与ActionBar的颜色有适当的对比度。为了辅助达到这一点 Action Bar Icon Pack包含了一些用在ActionBar上的标准的功能按钮。
自定义ActionBar的背景色 为了改变ActionBar的背景色需要创建一个自定义的主题然后重写actionBarStyle属性。这个属性指向了其它的背景样式,您可以在其它背景样式中重写background属性来给ActionBar指定一个图像资源。
如果APP使用了navigation tabs或者 split action bar你也可以分别通过backgroundStacked和backgroundSplit属性指定他们的背景色。 注意: 选择适合的父类主题对于自定义主题来说很重要当继承主题之后所有的样式都会被继承下来。如果没有父类主题除非很明确的声明了每一项样式否则ActionBar会丢失很多样式属性。 为Android 3.0及以上版本定义
当仅仅支持了Android 3.0及更高的版本你可以像这样定义ActionBar的背景
?xml version1.0 encodingutf-8?
resources!-- the theme applied to the application or activity --style nameCustomActionBarThemeparentandroid:style/Theme.Holo.Light.DarkActionBaritem nameandroid:actionBarStylestyle/MyActionBar/item/style!-- ActionBar styles --style nameMyActionBarparentandroid:style/Widget.Holo.Light.ActionBar.Solid.Inverseitem nameandroid:backgrounddrawable/actionbar_background/item/style
/resources
然后应用这个主题到整个APP中或者是单个Activity中
application android:themestyle/CustomActionBarTheme ... /
为Android 2.1及以上版本定义
当使用了支持库它的修改方式和上面很相似
?xml version1.0 encodingutf-8?
resources!-- the theme applied to the application or activity --style nameCustomActionBarThemeparentstyle/Theme.AppCompat.Light.DarkActionBaritem nameandroid:actionBarStylestyle/MyActionBar/item!-- Support library compatibility --item nameactionBarStylestyle/MyActionBar/item/style!-- ActionBar styles --style nameMyActionBarparentstyle/Widget.AppCompat.Light.ActionBar.Solid.Inverseitem nameandroid:backgrounddrawable/actionbar_background/item!-- Support library compatibility --item namebackgrounddrawable/actionbar_background/item/style
/resources
然后应用这个主题到整个APP中或者是单个Activity中
application android:themestyle/CustomActionBarTheme ... /
自定义字体颜色
为了改变ActionBar上的字体颜色你需要单独重写text元素的每一个属性
ActionBar标题创建自定义的样式然后指定textColor的值然后将这个样式应用到你自己定义的主题actionBarStyle中的titleTextStyle属性里。 注意:如果要使用应用到titleTextStyle中的自定义样式那么应该使这个样式继承TextAppearance.Holo.Widget.ActionBar.Title。 ActionBar的标签重写主题中的actionBarTabTextStyle。ActionBar中的按钮重写主题中的actionMenuTextColor。
为Android 3.0及以上版本定义
当仅仅支持了Android 3.0及更高的版本你的XML风格文件应该使这样的
?xml version1.0 encodingutf-8?
resources!-- the theme applied to the application or activity --style nameCustomActionBarThemeparentstyle/Theme.Holoitem nameandroid:actionBarStylestyle/MyActionBar/itemitem nameandroid:actionBarTabTextStylestyle/MyActionBarTabText/itemitem nameandroid:actionMenuTextColorcolor/actionbar_text/item/style!-- ActionBar styles --style nameMyActionBarparentstyle/Widget.Holo.ActionBaritem nameandroid:titleTextStylestyle/MyActionBarTitleText/item/style!-- ActionBar title text --style nameMyActionBarTitleTextparentstyle/TextAppearance.Holo.Widget.ActionBar.Titleitem nameandroid:textColorcolor/actionbar_text/item/style!-- ActionBar tabs text styles --style nameMyActionBarTabTextparentstyle/Widget.Holo.ActionBar.TabTextitem nameandroid:textColorcolor/actionbar_text/item/style
/resources
为Android 2.1及以上版本定义
当使用了支持库你的XML风格文件应该使这样的
?xml version1.0 encodingutf-8?
resources!-- the theme applied to the application or activity --style nameCustomActionBarThemeparentstyle/Theme.AppCompatitem nameandroid:actionBarStylestyle/MyActionBar/itemitem nameandroid:actionBarTabTextStylestyle/MyActionBarTabText/itemitem nameandroid:actionMenuTextColorcolor/actionbar_text/item!-- Support library compatibility --item nameactionBarStylestyle/MyActionBar/itemitem nameactionBarTabTextStylestyle/MyActionBarTabText/itemitem nameactionMenuTextColorcolor/actionbar_text/item/style!-- ActionBar styles --style nameMyActionBarparentstyle/Widget.AppCompat.ActionBaritem nameandroid:titleTextStylestyle/MyActionBarTitleText/item!-- Support library compatibility --item nametitleTextStylestyle/MyActionBarTitleText/item/style!-- ActionBar title text --style nameMyActionBarTitleTextparentstyle/TextAppearance.AppCompat.Widget.ActionBar.Titleitem nameandroid:textColorcolor/actionbar_text/item!-- The textColor property is backward compatible with the Support Library --/style!-- ActionBar tabs text --style nameMyActionBarTabTextparentstyle/Widget.AppCompat.ActionBar.TabTextitem nameandroid:textColorcolor/actionbar_text/item!-- The textColor property is backward compatible with the Support Library --/style
/resources
自定义标签指示器 如果要改变导航标签navigation tabs的指示器的话创建一个activity主题然后重写actionBarTabStyle属性。这个属性会指向其它样式资源。这个样式资源需要重写background属性然后并设置它的值为一个状态列表图像资源。 Note:状态列表图像是很重要的。它可以在标签选中的情况下使用户区别出选中的标签与未选中便签的不同从而判断是哪个便签被选中。有关如何创建一个作用于展示多种按钮状态的图像资源请参见State List文档。 举个例子以下是一个状态列表图像资源文件的内容。这里声明了用作于ActionBar标签的若干个状态每个状态都指定了一张背景图
?xml version1.0 encodingutf-8?
selector xmlns:androidhttp://schemas.android.com/apk/res/android
!-- STATES WHEN BUTTON IS NOT PRESSED --!-- Non focused states --item android:state_focusedfalse android:state_selectedfalseandroid:state_pressedfalseandroid:drawabledrawable/tab_unselected /item android:state_focusedfalse android:state_selectedtrueandroid:state_pressedfalseandroid:drawabledrawable/tab_selected /!-- Focused states (such as when focused with a d-pad or mouse hover) --item android:state_focusedtrue android:state_selectedfalseandroid:state_pressedfalseandroid:drawabledrawable/tab_unselected_focused /item android:state_focusedtrue android:state_selectedtrueandroid:state_pressedfalseandroid:drawabledrawable/tab_selected_focused /
!-- STATES WHEN BUTTON IS PRESSED --!-- Non focused states --item android:state_focusedfalse android:state_selectedfalseandroid:state_pressedtrueandroid:drawabledrawable/tab_unselected_pressed /item android:state_focusedfalse android:state_selectedtrueandroid:state_pressedtrueandroid:drawabledrawable/tab_selected_pressed /!-- Focused states (such as when focused with a d-pad or mouse hover) --item android:state_focusedtrue android:state_selectedfalseandroid:state_pressedtrueandroid:drawabledrawable/tab_unselected_pressed /item android:state_focusedtrue android:state_selectedtrueandroid:state_pressedtrueandroid:drawabledrawable/tab_selected_pressed /
/selector
为Android 3.0及以上版本定义
当仅仅支持了Android 3.0及更高的版本你的XML风格文件应该使这样的
?xml version1.0 encodingutf-8?
resources!-- the theme applied to the application or activity --style nameCustomActionBarThemeparentstyle/Theme.Holoitem nameandroid:actionBarTabStylestyle/MyActionBarTabs/item/style!-- ActionBar tabs styles --style nameMyActionBarTabsparentstyle/Widget.Holo.ActionBar.TabView!-- tab indicator --item nameandroid:backgrounddrawable/actionbar_tab_indicator/item/style
/resources
为Android 2.1及以上版本定义
当使用了支持库你的XML风格文件应该使这样的
?xml version1.0 encodingutf-8?
resources!-- the theme applied to the application or activity --style nameCustomActionBarThemeparentstyle/Theme.AppCompatitem nameandroid:actionBarTabStylestyle/MyActionBarTabs/item!-- Support library compatibility --item nameactionBarTabStylestyle/MyActionBarTabs/item/style!-- ActionBar tabs styles --style nameMyActionBarTabsparentstyle/Widget.AppCompat.ActionBar.TabView!-- tab indicator --item nameandroid:backgrounddrawable/actionbar_tab_indicator/item!-- Support library compatibility --item namebackgrounddrawable/actionbar_tab_indicator/item/style
/resources 更多资源 ActionBar指南列出了更多ActionBar的风格属性。Styles and Themes指南可以学习到主题样式的工作原理。移步Android Action Bar Style Generator查看更多的ActionBar完整样式。