博客官网链接
http://developer.android.com/training/basics/actionbar/index.html
Action Bar即手机app上面的一行东东,类似如网页的标题和菜单。
官网上说利用它有如下三个作用
1. 现实用户所在位置(操作记录)
2.访问重要的动作(比如说搜索和设置)
3.可以添加下拉和导航
一、设置Action Bar
从Android 3.0 (API level 11)开始,action bar 包含在所有的使用了Theme.Holo 或者它的子主题的Activities中。
你可以从AndroidManifest.xml中的<uses-sdk>查看自己使用了哪个级别的SDK
二、添加 Action Button
在/res/menu/main.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>
@drawable 就是你的图标,你修要弄个图标拷贝到/res/drawable中,drawable-**是值不同像素大小的图片以方便你的APP支持不同的手机屏幕。
@+id后面跟组件ID,这样你就可以通过findViewByID在程序中找到这个组件
这时候如果你运行你的程序你会看到在你的MainActivity上方多了一个查询的图标,接下来为这个图标添加相应事件。
/src/..../MainActivity.java ,加入如下方法
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle presses on the action bar items switch (item.getItemId()) { case R.id.action_search: openSearch(); return true; case R.id.action_settings: openSettings(); return true; default: return super.onOptionsItemSelected(item); } }
当点击了search 按钮是,会调用openSearch方法
三、为Action Button设置样式
略
四、让Action Bar 漂浮起来
默认情况下Action Bar 在Activity 窗口的上面,你可以通过设置和编程让它浮动起来。
为了让开始的时候,尽量的简单,这些东西先不看了。以后有时间一个组件和一个类来学习。
相关推荐
Android, the next-generation open mobile platform from Google and the Open Handset Alliance, is poised to become a significant player in the mobile device market. The Android platform gives developers...
Tutorial #7 - Setting Up the Action Bar Android’s Process Model Activities and Their Lifecycles Tutorial #8 - Setting Up An Activity The Tactics of Fragments Tutorial #9 - Starting Our Fragments ...
"Adding Drop down navigation"是关于如何在Android应用程序中实现这种功能的一个主题,通常与Action Bar紧密相关。Action Bar是Android系统中一个重要的界面组件,它位于应用顶部,用于显示应用的标识、标题以及...
Adding an Action Bar to the Earthquake Monitor Creating and Using Menus and Action Bar Action Items Refreshing the Earthquake Monitor Going Full Screen Introducing Dialogs Let's Make a Toast ...
The Action Bar Shared Preferences and Updating Status Fragment The Filesystem Explained Summary Chapter 10 Services Our Example Service: RefreshService Pulling Data from Yamba Summary Chapter 11 ...
You'll build a Twitter-like application throughout the course of this book, adding new features with each chapter. Along the way, you'll also create your own toolbox of code patterns to help you ...
You will begin with the basic concepts of Android game development, a brief history of Android games, the building blocks of Android games in Unity 5, and the basic flow of games. You will configure ...
Adding an action bar icon Adding menu items Using custom animations The application uses Helper Classes from the example project by Google. Requirements Android SDK. Android 5.1 (API 22) . ...
After adding the library, you can add an IconEditText like so: XML <!-- Note the declaration of the `widget` namespace. --> Options The IconEditText currently supports the following ...
android好书系列,我目前找了两本,先贡献给大家。以后如果有好的资源,再上传和大家分享。 本资源是第一本。 这是一本学习android的好书,我浏览了,是老外著的,高清晰的pdf。为了方便大家学习android,我将本书所...
You may get this library by adding the following in the dependency section of your build.gradle file: compile 'com.tf.library.tabs:tftabs:2.1.0' Or you may copy the following files from the given ...
The document "Decompiling Android.pdf" delves into the complex world of decompiling on the Android platform, a topic of significant importance for developers, security experts, and anyone interested ...
Make sure to re-run gclient sync after adding this to download the tools. Env vars need to be set up to target Android; easiest way to do this is to run (from the libjingle trunk directory): . ./build...
This book covers Android app design fundamentals in Android Studio using Java programming language. The author assumes you have no experience in app development. The book starts with the installation ...
uniauto-appupdate ...Adding the maven plugin To enable installing into local maven repository and JitPack you need to add the android-maven plugin: Add classpath 'com.github.dcendents:android-maven
Further in Part 3, the reader will also learn advanced topics such as adding integration to Twitter to process its streaming data by combining it with stock data. What you will learn Setup the ...