About ActionBar

The action bar is one of the most important design elements you can implement for your app's activities. It provides several user interface features that make your app immediately familiar to users by offering consistency between other Android apps. Key functions include:

A dedicated space for giving your app an identity and indicating the user's location in the app.

Access to important actions in a predictable way (such as Search).

Support for navigation and view switching (with tabs or drop-down lists).

ActionBar 的创建

如果最低兼容版本小于3.0 --> Support Android 2.1 and Above

Setting Up the Action Bar

1.引用V7-appcompat
>   To get started, read the Support Library Setup document and set up the v7 appcompat library
2.Activity继承ActionBarActivity 
> Update your activity so that it extends ActionBarActivity
3.在配置清单文件中,android:theme="@style/Theme.AppCompat.Light"
> In your manifest file, update either the <application> element or individual <activity> elements to use one of the Theme.AppCompat themes.

Adding Action Buttons

Add an <item> element for each item you want to include in the action bar. 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>

如果最低兼容版本大于3.0 --> Support Android 3.0 and Above Only

Setting Up the Action Bar

在配置清单文件中,android:theme="@android:style/Theme.Holo..."

Adding Action Buttons

Add an <item> element for each item you want to include in the action bar. For example:

res/menu/main_activity_actions.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Search, should appear as action button -->
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
android:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:showAsAction="never" />
</menu>

ActionBar的搜索功能

在Activity中,增加以下代码:

	public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.activity_main, menu); // 不兼容低版本
SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
searchView.setOnQueryTextListener(this); // 搜索的监听 return super.onCreateOptionsMenu(menu);
}
	public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.action_search:
openSearch();
return true;
default:
return super.onOptionsItemSelected(item);
}
}

ActionBar 的简单使用的更多相关文章

  1. ActionBar的简单使用

    只简单实现了一下ActionBar的使用,在右上角添加两个ActionBar,在左上角实现默认的返回箭头,类似于微信朋友圈的 这是MainActivity的代码: public class MainA ...

  2. 安卓---achartengine图表----简单调用----使用view显示在自己的布局文件中----actionBar的简单设置

    AChartEngine 是一个安卓系统上制作图表的框架,关于它的介绍大家可以百度,也可以参考下面这篇博客http://blog.csdn.net/lk_blog/article/details/76 ...

  3. [Android]AndroidDesign中ActionBar探究2 嵌入Fragment

    上一节我们只是简单了介绍了Android Design风格中的ActionBar的简单实用,如添加MenuItem,这节我们会进一步了解ActionBar的其他功能. 在Android Develop ...

  4. Android M 控件:Snackbar、Toolbar、TabLayout、NavigationView

    Snackbar Snackbar提供了一个介于Toast和AlertDialog之间轻量级控件,它可以很方便的提供消息的提示和动作反馈.Snackbar的使用与Toast的使用基本相同: Snack ...

  5. 001.android初级篇之ToolBar

    官方的最新support library v7中提供了新的组件ToolBar,用来替代之前的ActionBar,实现更为弹性的设计在 material design 也对之做了名称的定义:App ba ...

  6. 美好头标ToolBar

    ActionBar我相信是每一位合格的程序员都用过的组件,也是每一个程序员都会抱怨的组件,因为他不能实现复杂的自定义.为此Google推出了比ActionBar更为美好的组件ToolBar. 本文重点 ...

  7. Android Material Design之Toolbar与Palette

    转:http://blog.csdn.net/jdsjlzx/article/details/41441083 前言 我们都知道Marterial Design是Google推出的全新UI设计规范,如 ...

  8. android Material Design详解

    原文地址:http://blog.csdn.net/jdsjlzx/article/details/41441083/ 前言 我们都知道Marterial Design是Google推出的全新UI设计 ...

  9. [安卓] 18、一个简单的例子做自定义动画按钮和自定义Actionbar

    在做安卓UI的时候有时候需自定义具有动画效果的按钮或需要自定义一下actionbar~ 本节用一个简单的demo讲如何自定义具有动画效果的按钮,以及个性化的actionbar 下面是效果: 其中: △ ...

随机推荐

  1. PsLookupProcessByProcessId分析

    本文是在讨论枚举进程的时候产生的,枚举进程有很多方法,Ring3就是ZwQuerySystemInformation(),传入SysProcessesAndThreadsInformation这个宏, ...

  2. SQLserver锁和事务隔离级别的比较与使用(转)

    SQLserver锁和事务隔离级别的比较与使用(转) http://www.cnblogs.com/chenlulouis/archive/2010/12/06/1898014.html http:/ ...

  3. 移植FreeModbus+ModbusMaster+STM32至RT-Thread(初步)

    一.项目描述 目前操作系统在嵌入式软件行业非常流行,在工控组网方面,以后可能会经常使用到Modbus主机+操作系统.Modbus从机+操作系统甚至Modbus主机+Modbus从机+操作系统.但是操作 ...

  4. 非IE内核浏览器支持activex插件

    之前在一个B/S项目中遇到一个需求,就是客户需要在页面上对报表的布局以及显示内容,进行自定义.最后决定使用activex技术来实现.众所周知,activex是微软搞得,因此只有ie内核的浏览器才能支持 ...

  5. 关于Struts2的客户端校验的FreeMarker template error!

    把<s:form action="login" namespace="/" validate="true" >改为 <s: ...

  6. codeforces GYM 100114 J. Computer Network tarjan 树的直径 缩点

    J. Computer Network Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Des ...

  7. Codeforces Gym 100338I TV Show 傻逼DFS,傻逼题

    Problem I. TV ShowTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest ...

  8. android数据库操作之直接读取db文件

    在对数据库操作时,常用的有两种方法: 1.在代码中建库.建表: 2.直接将相关库.表建立好,将db文件拷贝至assets目录下:     现在来看看第二种方法:   private String Ge ...

  9. SHELL 详解

    http://blog.csdn.net/vah101/article/details/6173488 ( a=2;b=4;c=9; ) 子shell 环境 { a=2;b=4;c=9; } 当前sh ...

  10. C#的空接合运算符 三目运算符

    1.空接合运算符:操作数1??操作数2: 2.第一个操作数必须是一个可空类型或引用类型,第二个操作数必须与第一个操作数类型相同,或者可以隐含的转换为第一个操作数的类型: 3.如果第一个操作数不为nul ...