对于ActionBar,谷歌文档介绍了2种写法,其中2.1是带v7包。


对于3.0(使用系统自带的主题) ---带应用的icon

If you've created a custom theme, be sure it uses one of the Theme.Holo themes

as its parent.

android:theme="@android:style/Theme.Holo"


对于2.1带v7包(使用v7包里的主题) ---不带应用的icon

第1:Activity要继承自ActionBarActivity

第2:Activity的主题必须是AppCompat

<activity android:theme="@style/Theme.AppCompat.Light" ... >

publicclassMainActivityextendsActionBarActivity{...}


千万要注意的问题:AppCompatActivity必须与AppCompat的主题配合使用,不能混搭。


>>>>对于使用了支持库的,有一个问题需要注意一下:

只有AppComatActivity才有showAsAction这个属性,Activity只有菜单,并不会将菜单里的条目做

成Action。

If your app is using the Support Library for compatibility on versions as low as Android 2.1, the showAsAction attribute is not available from the android: namespace. Instead this attribute is provided by the Support Library and you must define your own XML namespace and use that namespace as the attribute prefix. (A custom XML namespace should be based on your app name, but it can be any name you want and is only accessible within the scope of the file in which you declare it.) For example:

res/menu/main_activity_actions.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<!-- Search, should appear as action button -->
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
yourapp:showAsAction="ifRoom" />
...
</menu>


>>>>为Activity增加返回按钮:

方式1:隐式的进行绑定

先配置Activity,包括它的父Activity(也就是它返回跳转到的那个Activity)

<!-- A child of the main activity -->
<activity
android:name=".Activity2"
android:label="@string/title_activity_display_message"
android:parentActivityName=".MainActivity" >
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>

然后

(BundlesavedInstanceState){.onCreate(savedInstanceState)setContentView(R.layout.)getSupportActionBar().setDisplayHomeAsUpEnabled()}


》》Styling the Action Bar(做出有风格的ActionBar)

1.Use an Android Theme

###不使用支持库的情况


    • Theme.Holo for a "dark" theme. 工具栏和主面板都是黑色主题(API11)

    • Theme.Holo.Light for a "light" theme. 工具栏和主面板都是白色主题 (API11)

    • Theme.Holo.Light.DarkActionBar 工具栏为黑色,主面板为白色(API14


      When using the Support Library, you must instead use theTheme.AppCompat themes:


    • Theme.AppCompat for the "dark" theme.

    • Theme.AppCompat.Light for the "light" theme.

    • Theme.AppCompat.Light.DarkActionBar for the light theme with a dark action bar

2.Customize the Background


3.Customize the Text Color


4.Customize the Tab Indicator

上面的我也没有写,具体请看谷歌文档Develop-Training-Adding Action Bar-Styling the ActionBar


>>Overlaying the Action Bar(使ActionBar堆叠在主面板之上)

这样做的好处:一旦ActionBar hide或者show的时候,不会引起主界面的重绘,效率高。

需要考虑的一个问题:主面板要设置个margin,不让ActionBar遮盖住主界面。

android:paddingTop="?android:attr/actionBarSize"



更多相关文章

  1. Android(安卓)L+ Theme 与 Toolbar
  2. android字符串处理(Mms模块短信内容解析)
  3. Android(安卓)Q 深色主题
  4. Android(安卓)Studio (IntelliJ/IDEA)在AndroidSDK Leve22报except
  5. Android(安卓)4.1 Jelly Bean(果冻豆) SDK4.1最新下载
  6. Android官方开发文档Training系列课程中文版:支持不同的设备之支
  7. Android修改主题,去掉ActionBar、TitleBar
  8. 使用主题Theme实现Android沉浸式状态栏
  9. Android应用程序换肤实现系列(二)

随机推荐

  1. 前任都能看懂的分库分表方案
  2. 苹果Mac强大的批量重命名工具:A Better Fi
  3. python入门之 字典算法实现及操作
  4. 生病期间肝了3万字的Spring容器启动流程
  5. 敖丙读者字节、滴滴面经(已拿offer)
  6. 0322作业(选择器的优先级,id,class,tag);
  7. 0322作业-CSS基础1
  8. nginx代理
  9. 实力认证|Authing 入选 2021 《中国网络安
  10. redis与lua