zoukankan      html  css  js  c++  java
  • Android菜鸟的成长笔记(28)——Google官方对Andoird 2.x提供的ActionBar支持

    在Google官方Android设计指南中(链接:http://www.apkbus.com/design/get-started/ui-overview.html)有一个新特性就是自我标识,也就是宣传自己,所以非常多应用如今也自然的使用ActionBar并提供自己的logo.

    微信的应用:


    Google的Android设计指南中是这样说的:应用的 启动图标 作为启动应用的入口是展示 logo 的最佳场所。你也能够将启动图标放置在 操作栏 上,从而保证在应用内的全部页面上都能看到它。

    在使用ActionBar的时候。会发现一个问题。

    在3.0曾经SDK中是不支持ActionBar的,所以假设手机apk要兼容2.2或2.3的手机就须要用一个开源的项目ActionBarSherlock,详细用法例如以下:

    1、下载开源包:http://actionbarsherlock.com/usage.html

    2、导入到Eclipse中(和导入项目步骤同样,记得勾选Is Library)


    3、在项目中引用(properties->android->add  加进去


    4、改动主题为@Style/Theme.Sherlock.Light(或其子类)

    5、继承SherlockActivity。

    6、使用getSupportActionBar()获取ActionBar对象。

    上面方法就能够实现低版本号使用ActionBar的问题。可是Goole去年推出了自己的兼容包,使用起来更加方便。以下我们就来看看怎样使用support_v7。

    1、和上面一样下载和导入appcompat_7.x兼容包(假设是官方最新的sdk开发工具则提供)

    2、在项目中引用:


    3、改动主题为@style/Theme.AppCompat(或其子类)

    4、改动menu/文件夹下相应的xml文件

    <?

    xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:alpha="http://schemas.android.com/apk/res-auto"> <!-- Search, should appear as action button --> <item android:id="@+id/action_search" android:icon="@drawable/ic_action_refresh" android:title="刷新" alpha:showAsAction="always"/> <!-- Settings, should always be in the overflow --> <item android:id="@+id/action_add" android:title="分享" android:icon="@drawable/ic_action_share" alpha:showAsAction="always" /> <item android:id="@+id/action_settings" android:title="很多其它" android:icon="@drawable/ic_action_overflow" alpha:showAsAction="always"> <menu > <group > <item android:id="@+id/item1" android:title="个人中心" android:icon="@drawable/ic_action_share"/> <item android:id="@+id/item2" android:title="设置" android:icon="@drawable/ic_action_share"/> <item android:id="@+id/exit_system" android:title="退出" android:icon="@drawable/ic_action_share"/> </group> </menu> </item> </menu>

    5、继承自ActionBarActivity

    6、使用getSupportActionBar获取ActionBar对象。

    		ActionBar actionBar = getSupportActionBar();
    		actionBar.setDisplayShowHomeEnabled(true);
    		actionBar.setIcon(R.drawable.actionbar_icon);

    在Android 2.2和2.3手机上完美执行...


  • 相关阅读:
    asp .net 页面回车触发button 按钮事件
    Asp.netPost&Get转
    2012.8.16近期总结,1模态窗口回传重新被弹出2,清空缓存 3,
    面试感言
    2012.6.27近期总结,1.sql字符串转换(cast,CONVERT )调用wcf服务,关闭模态窗口刷新付页面
    self
    空指针
    枚举和结构体
    typedef
    指针
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5322613.html
Copyright © 2011-2022 走看看