Action bar是一个标识应用程序和用户位置的窗口功能,并且给用户提供操作和导航模式。在大多数的情况下,当你需要突出展现用户行为或全局导航的activity中使用action bar,因为action bar能够使应用程序给用户提供一致的界面,并且系统能够很好根据不同的屏幕配置来适应操作栏的外观。你能够用ActionBar的对象的API来控制操作栏的行为和可见性,这些API被添加在Android3.0(API 级别 11)中。
从Android3.0(API级别 11)开始,Action bar被包含在所有的使用Theme.Hole主题的Activity(或者是这些Activity的子类)中,当targetSdkVersion或minSdkVersion属性被设置为“11”或更大的数值是,这个主题是默认的主题一。如:
Holo.Light.DarkActionBar 风格是黑色背景白色字体 对应最低版本是14
<uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="18"
android:Theme.Holo.Light 主题 对应版本11
</pre>最低版本是14以上的系统会自动到values-14包下找到相关主题,如果版本大于14的话,系统会直接找最大的,也就是values-14. <p><span style="font-family:Arial;color:#333333;LINE-HEIGHT: 26px"><span style="font-size:18px;"></span></span><pre class="html" name="code" snippet_file_name="blog_20151119_3_6893304" code_snippet_id="443132"> android:theme="@style/AppBaseTheme"
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
在清单文件中引用系统主题
android:theme="@android:style/android:Theme.Holo.Light.DarkActionBar"
android:theme="@style/CustomActionBarTheme"
删除actionbar
<activity android:theme="@android:style/Theme.Holo.NoActionBar">
或者代码 把actionbar隐藏
ActionBar actionBar = getActionBar();
actionBar.hide();
首先介绍3.0以上系统actionbar的使用
菜单项
<item
android:id="@+id/action_share"
android:actionProviderClass="android.widget.ShareActionProvider"
android:showAsAction="ifRoom"
android:title="@string/share"/>
<item
android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:showAsAction="ifRoom"
android:title="@string/search"/>
<item
android:id="@+id/action_setting"
android:showAsAction="never"
android:title="@string/setting"/>
showAsAc