博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android学习系列(40)--Android主题和样式之系统篇(下)
阅读量:5757 次
发布时间:2019-06-18

本文共 8866 字,大约阅读时间需要 29 分钟。

11)Widget样式(Widget Style)

特别说明,此处定义大量的系统内置控件的样式,对于重写原生控件的样式具有很大的参考价值。

@android:style/Widget.AbsListView
@android:style/Widget.AutoCompleteTextView
@android:style/Widget.CompoundButton.CheckBox
@android:style/Widget.CheckedTextView
@android:style/Widget.ListView.DropDown
@android:style/Widget.EditText
@android:style/Widget.ExpandableListView
@android:style/Widget.ExpandableListView.White
@android:style/Widget.Gallery
@android:style/Widget.GestureOverlayView
@android:style/Widget.GridView
@android:style/Widget.ImageButton
@android:style/Widget.ImageWell
@android:style/Widget.ListView
@android:style/Widget.ListView.White
@android:style/Widget.PopupWindow
@android:style/Widget.ProgressBar
@android:style/Widget.ProgressBar.Horizontal
@android:style/Widget.ProgressBar.Small
@android:style/Widget.ProgressBar.Small.Title
@android:style/Widget.ProgressBar.Large
@android:style/Widget.ProgressBar.Inverse
@android:style/Widget.ProgressBar.Small.Inverse
@android:style/Widget.ProgressBar.Large.Inverse
@android:style/Widget.SeekBar
@android:style/Widget.RatingBar
@android:style/Widget.RatingBar.Indicator
@android:style/Widget.RatingBar.Small
@android:style/Widget.CompoundButton.RadioButton
@android:style/Widget.ScrollView
@android:style/Widget.HorizontalScrollView
@android:style/Widget.Spinner
@android:style/Widget.Spinner.DropDown
@android:style/Widget.CompoundButton.Star
@android:style/Widget.TabWidget
@android:style/Widget.TextView
@android:drawable/popup_inline_error
@android:drawable/popup_inline_error_above
@android:style/Widget.WebTextView
@android:style/Widget.WebView
@android:style/Widget.DropDownItem
@android:style/Widget.DropDownItem.Spinner
@android:style/Widget.TextView.SpinnerItem
@android:style/TextAppearance.Widget.DropDownHint
@android:style/Widget.KeyboardView
@android:drawable/quickcontact_badge_overlay_dark
@android:style/Widget.QuickContactBadge.WindowSmall
@android:style/Widget.QuickContactBadge.WindowMedium
@android:style/Widget.QuickContactBadge.WindowLarge
@android:style/Widget.QuickContactBadgeSmall.WindowSmall
@android:style/Widget.QuickContactBadgeSmall.WindowMedium
@android:style/Widget.QuickContactBadgeSmall.WindowLarge
@android:style/Widget.ListPopupWindow
@android:style/Widget.PopupMenu
@android:style/Widget.ActivityChooserView
@android:style/Widget.DeviceDefault.MediaRouteButton
12)Preference样式(Preference Style)

说明,设置类界面样式

@android:style/Preference.PreferenceScreen
@style/PreferenceFragment
@android:style/Preference.Category
@android:style/Preference
@android:style/Preference.Information
@android:style/Preference.CheckBoxPreference
@android:style/Preference.SwitchPreference
@android:style/Preference.DialogPreference.YesNoPreference
@android:style/Preference.DialogPreference
@android:style/Preference.DialogPreference.EditTextPreference
@android:style/Preference.RingtonePreference
@android:layout/preference_child
@style/PreferencePanel
@style/PreferenceHeaderPanel
@style/PreferenceHeaderList
@style/PreferenceFragmentList
@dimen/preference_fragment_padding_side
@android:drawable/panel_bg_holo_dark
13)Search控件样式( Search Style)
@android:color/search_widget_corpus_item_background
@android:drawable/spinner_dropdown_background
@drawable/textfield_searchview_holo_dark
@drawable/textfield_searchview_right_holo_dark
@android:drawable/ic_clear
@android:drawable/ic_search
@android:drawable/ic_go
@android:drawable/ic_voice_search
@android:drawable/ic_commit_search_api_holo_dark
?attr/selectableItemBackground
@style/Theme.SearchBar
14)ActionBar样式( Action bar Style)
@android:style/Widget.Spinner.DropDown
@android:style/Widget.ActionButton
@android:style/Widget.ActionButton.Overflow
@android:drawable/cab_background_top_holo_dark
@null
@android:drawable/ic_menu_close_clear_cancel
@android:drawable/ic_menu_cut_holo_dark
@android:drawable/ic_menu_copy_holo_dark
@android:drawable/ic_menu_paste_holo_dark
@android:drawable/ic_menu_selectall_holo_dark
@android:drawable/ic_menu_share_holo_dark
@android:drawable/ic_menu_find_holo_dark
@android:drawable/ic_menu_search
@style/Widget.ActionBar.TabView
@style/Widget.ActionBar.TabBar
@style/Widget.ActionBar.TabText
@style/Widget.ActionMode
@style/Widget.ActionButton.CloseMode
@android:style/Widget.ActionBar
?android:attr/actionBarStyle
@dimen/action_bar_default_height
?android:attr/popupWindowStyle
@android:style/TextAppearance.Holo.Widget.ActionBar.Menu
?android:attr/textColorPrimary
@null
?android:attr/dividerVertical
?android:attr/selectableItemBackground
@drawable/divider_vertical_dark
@drawable/divider_vertical_dark
@android:style/ButtonBar
?android:attr/buttonStyle
@android:style/SegmentedButton
15)其它样式
@android:style/Widget.PreferenceFrameLayout
@style/Widget.NumberPicker
@style/Widget.CalendarView
@style/Widget.TimePicker
@style/Widget.DatePicker
@android:drawable/scrollbar_handle_accelerated_anim2
@null
@android:drawable/menu_submenu_background
@android:drawable/menu_submenu_background
floating
@android:color/primary_text_dark
@android:style/Pointer
@android:drawable/view_accessibility_focused
5、一些细化的style(特别是大量的控件的样式)定义在了styles.xml

themes.xml偏全局,styles.xml偏细化。

我直接贴出链接地址,大家查看:
https://github.com/CyanogenMod/android_frameworks_base/blob/cm-11.0/core/res/res/values/styles.xml

6、我们能做什么

两点说明:

  • 我们可以根据这些样式改变系统控件的样式
  • 但不是所有的样式我们都可以修改,比如AlertDialog,布局和一些属性都是写在硬编码中了,我们是无法修改的。

通过学习这些主题和样式,我们能准确的把握我们能定制哪些样式,哪些我们不能定制,是否需要重新写一套替代的UI控件。

这个在项目决策和进度评估上是非常重要的。

7、简单例子

以CheckBox为例,CheckBox使用的样式我们猜测使用checkboxStyle(实际上从CheckBox源码分析看,它确实使用的是checkboxStyle):

@android:style/Widget.CompoundButton.CheckBox

查看styles.xml中的Widget.CompoundButton.CheckBox的定义:

继续在themes.xml中查看listChoiceIndicatorMultiple的定义,不同的主题可能定义会有不同,我们选取最基本的那个:

@android:drawable/btn_check

CheckBox的样式就是这个btn_check:

我把这个btn_check.xml拷贝到Android工程的drawable目录下,同时把一些新的checkbox的图片也准备好,拷贝到drawable-hdpi目录下:

292126416441599.png
同时在工程的styles.xml覆盖checkBox style:

我截取2个不同的状态的效果图如下,

292138112377340.png

8、小结

本文纯从主题和样式对系统样式,特别是控件样式笼统的描述了一遍。

如果结合系统源码和主题样式一起学习,可以更深入的了解android主题机制。

转载地址:http://fhpkx.baihongyu.com/

你可能感兴趣的文章
zt:缓存一致性(Cache Coherency)入门 cach coherency
查看>>
洛谷P5206 [WC2019] 数树(生成函数+容斥+矩阵树)
查看>>
关于autoconf
查看>>
《大话设计模式》读书笔记-第28章 访问者模式
查看>>
Dependency Injection in SignalR – ASP.NET SignalR
查看>>
ThreadPoolExecutor源码解析
查看>>
URL some
查看>>
SUSE10 SP2/SP3 无规律死机故障解决
查看>>
统计查询
查看>>
PDFBox
查看>>
工作授权系统
查看>>
Codeforces D - Ithea Plays With Chtholly
查看>>
CSS3---first-child或者nth-child(1) 不起作用的原因
查看>>
openstack libtray
查看>>
关于TreeView(CS/BS)解决方案
查看>>
顶帽变化(转载)
查看>>
如何学好C++语言(转)
查看>>
PTA基础编程题目集6-7 统计某类完全平方数 (函数题)
查看>>
计算20140215
查看>>
2014022101
查看>>