博客官网链接
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 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 ...
Adding the Android Samples Using the SDK Manager 56 Adding the Snake Project to Your Android IDE Workspace 57 Creating an AVD for Your Snake Project 61 Creating a Launch Configuration for Your Snake...
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 ...
If you're new to the Android mobile operating system, Learning Android is the perfect way to master the fundamentals. Written by an expert who's taught Android to thousands of people in large ...
javaFx 学习--之Adding Dynamic Behavior(加动态特性源码)
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 ...
Pro Android 4 shows you how to build real-world and fun mobile apps using the new Android SDK 4 (Ice Cream Sandwich), which unifies Gingerbread for smartphones, Honeycomb for tablets and augments ...
android好书系列,我目前找了两本,先贡献给大家。以后如果有好的资源,再上传和大家分享。 本资源是第一本。 这是一本学习android的好书,我浏览了,是老外著的,高清晰的pdf。为了方便大家学习android,我将本书所...
Since their release, Android has progressed with the debut of Android 4.0, adding better fonts, new User Interface and Experience (UI/UX) APIs, tablet considerations, multi-touch capabilities, multi-...
By gradually adding features to the game throughout the course of the book, you’ll learn about many aspects of Android programming including user interfaces, multimedia, and the Android life cycle. ...
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 ...
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...
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 ...