##Getting Started
-
Styling the Action Bar
-
ActionBar可以有tab,也可以有分离的底部bar,用于显示action items
-
使用Theme + Theme.Holo,暗黑系主题 + Theme.Holo.Light,光明系主题 + Theme.Holo.Light.DarkActionBar,光明系主题,暗黑系ActionBar +
<application android:theme="@android:style/Theme.Holo.Light" ... />+ 使用support library时- Theme.AppCompat,暗黑系
- Theme.AppCompat.Light
- Theme.AppCompat.Light.DarkActionBar + Android-Action-Bar-Icons
-
自定义背景 + standard:
<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar"> @style/MyActionBarandroid:actionBarStyle==>android:background+ support:actionBarStyle==>background+ 示例 ```xml<!-- Support library compatibility --> <item name="actionBarStyle">@style/MyActionBar</item> </style> <!-- ActionBar styles --> <style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"> <item name="android:background">@drawable/actionbar_background</item> <!-- Support library compatibility --> <item name="background">@drawable/actionbar_background</item> </style>
```
-
自定义文字颜色 + standard
- Action bar title:
android:actionBarStyle==>android:titleTextStyle==>android:textColor - Action bar tabs:
android:actionBarTabTextStyle==>android:textColor - Action buttons:
android:actionMenuTextColor+ support: 规则一样,去掉android:前缀(android:textColor不需要去掉前缀) + 示例 ```xml
- Action bar title:
</resources>
```
-
Customize the Tab Indicator(图标/左侧按钮) + standard:
<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat"> @style/MyActionBarTabs @style/MyActionBarTabs </style> <style name="MyActionBarTabs" parent="@style/Widget.AppCompat.ActionBar.TabView"> @drawable/actionbar_tab_indicator @drawable/actionbar_tab_indicator </style>android:actionBarTabStyle==>android:background+ 示例 ```xml
</resources>
```
- ActionBar全部style属性
- ActionBar Style Generator
- Overlaying the Action Bar
- hide/show可以控制隐藏/显示,但是直接使用会导致Activity重新layout
- 使用overlay mode可以避免重新layout,而使用带有透明度的ActionBar可以使得ActionBar底部的View也可见
- 起用overlay mode ```xml <style name="CustomActionBarTheme" parent="@android:style/Theme.AppCompat"> true true </style>
</resources>
```
- 设置root layout的顶部边距,使得其完全可见
+
android:paddingTop="?android:attr/actionBarSize"+android:paddingTop="?attr/actionBarSize" - 多语言支持:创建
/values/strings.xml,/values-es/strings.xml,/values-fr/strings.xml等资源文件夹,其中的资源定义为相同的id,则引用时会自动根据系统设置语言选择对应文件夹下的资源 - 多尺寸支持:
drawable-xhdpi,drawable-hdpi/...等等尺寸相关的资源 - 多系统版本支持
- minSdkVersion,targetSdkVersion
- 运行时检查:
Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB - Fragment之间通信
- 通过Activity间接实现,Activity实现接口,Fragment获取(
getActivity())、cast、调用 - EventBus