ActionBar 的简单使用
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 的简单使用的更多相关文章
- ActionBar的简单使用
只简单实现了一下ActionBar的使用,在右上角添加两个ActionBar,在左上角实现默认的返回箭头,类似于微信朋友圈的 这是MainActivity的代码: public class MainA ...
- 安卓---achartengine图表----简单调用----使用view显示在自己的布局文件中----actionBar的简单设置
AChartEngine 是一个安卓系统上制作图表的框架,关于它的介绍大家可以百度,也可以参考下面这篇博客http://blog.csdn.net/lk_blog/article/details/76 ...
- [Android]AndroidDesign中ActionBar探究2 嵌入Fragment
上一节我们只是简单了介绍了Android Design风格中的ActionBar的简单实用,如添加MenuItem,这节我们会进一步了解ActionBar的其他功能. 在Android Develop ...
- Android M 控件:Snackbar、Toolbar、TabLayout、NavigationView
Snackbar Snackbar提供了一个介于Toast和AlertDialog之间轻量级控件,它可以很方便的提供消息的提示和动作反馈.Snackbar的使用与Toast的使用基本相同: Snack ...
- 001.android初级篇之ToolBar
官方的最新support library v7中提供了新的组件ToolBar,用来替代之前的ActionBar,实现更为弹性的设计在 material design 也对之做了名称的定义:App ba ...
- 美好头标ToolBar
ActionBar我相信是每一位合格的程序员都用过的组件,也是每一个程序员都会抱怨的组件,因为他不能实现复杂的自定义.为此Google推出了比ActionBar更为美好的组件ToolBar. 本文重点 ...
- Android Material Design之Toolbar与Palette
转:http://blog.csdn.net/jdsjlzx/article/details/41441083 前言 我们都知道Marterial Design是Google推出的全新UI设计规范,如 ...
- android Material Design详解
原文地址:http://blog.csdn.net/jdsjlzx/article/details/41441083/ 前言 我们都知道Marterial Design是Google推出的全新UI设计 ...
- [安卓] 18、一个简单的例子做自定义动画按钮和自定义Actionbar
在做安卓UI的时候有时候需自定义具有动画效果的按钮或需要自定义一下actionbar~ 本节用一个简单的demo讲如何自定义具有动画效果的按钮,以及个性化的actionbar 下面是效果: 其中: △ ...
随机推荐
- Javascript高级篇-Function对象
1.引入 1.1Function是基于原型的对象 2.创建Function对象 2.1 var myFun = new Function("参数一","参数二" ...
- sunlime text 3 快捷键总结
Ctrl+D 选中光标所占的文本,继续操作则会选中下一个相同的文本. Alt+F3 选中文本按下快捷键,即可一次性选择全部的相同文本进行同时编辑.举个栗子:快速选中并更改所有相同的变量名.函数名等. ...
- Oracle使用goldengate分别向Oracle和mysql双路的单向复制
一.Oracle分别向Oracle和mysql双路的单向复制是在: ORACLE-mysql的单向复制基础上做的.http://blog.csdn.net/q947817003/article/det ...
- HDU 1999 不可摸数
/* 中文题意: 中文翻译: 题目大意:见红字(例如以下) 解题思路:打表,将每一个数的合数之和存在一个数组之中 难点具体解释:用两个for循环写的,第二个for循环主要是解释两个数相乘不超过这个最大 ...
- 前端js插件
jquery jquery官方 版本:v 2.1.0v 1.11.0 yquery 暂停更新 版本: v 1.6v 1.5 v 1.4v 1.3 v 1.2v 1.1 v 1.0 jQuery 原型插 ...
- C++ _access和_waccess的使用方法
C++ _access和_waccess的使用方法 概述 头文件:<io.h> 判断文件的访问权限 原型 int _access( const char *path, int mo ...
- Object-c中的属性和成员变量的关系详解
很多人在初学移动开发的时候会对object-c中的合成存取方法感到疑惑,此处尝试为看到本文有缘人答疑解惑,鄙人才疏学浅,难免有疏漏谬误之处,热烈欢迎诸位看官拍砖指点. 1.合成存取方法: OC为增加开 ...
- struts2.1笔记05:struts2开发环境的搭建
1.找到开发Struts应用需要使用到的jar文件. 首先我们要在myEclipse中新建一个Web Project,我们这里命名为"struts2".然后我们就要使用jar文件, ...
- python解决SNIMissingWarning和InsecurePlatformWarning警告
在想要获取https站点的资源时,会报出SNIMissingWarning和InsecurePlatformWarning警告 SNIMissingWarning: An HTTPS request ...
- iPhone screen size
iPhone 4 iPhone 5 iPhone 6 iPhone 6 Plus Display Size 3.5 in 4 in 4.7 in 5.5 in Screen Size 320 x ...