有一段时间没有写博文了,发现自己的博文的完整度不是非常好。就拿AndroidUI组件这一块。一直没有更新完。我会尽快更新。好了。不多说了,今天来看一下ActionBar。

依照以往的作风。知识点都以代码凝视的形式在源码中。

package com.gc.actionbardemo;
/**
* 1、活动条(ActionBar)是Android3.0的重要更新之中的一个。 ActionBar位于传统标题栏的位置
* 也就是显示的屏幕的顶部。ActionBar可显示应用的图标和Activity标题---也就是应用
* 程序顶部显示的内容。除此之外。ActionBar的右边还能够显示活动项。
* 2、ActionBar提供了例如以下功能
* (1)显示选项菜单的菜单项(将菜单项显示成Action Item)
* (2)使用程序图标作为返回Home主屏或向上的导航操作
* (3)提供交互式View作为Action View
* (4)提供基于Tab的导航方式,可用于切换多个Fragment
* (5)提供基于下拉的导航方式
* 3、假设希望关闭ActionBar。能够设置该应用的主题为Xxx.NoActionBar
* 4、一旦关闭了ActionBar。该Android应用将不能使用ActionBar
* 5、实际项目中。通常推荐使用代码来控制ActionBar显示、隐藏,ActionBar
* 提供了例如以下方法来控制显示、隐藏。
* show():显示ActionBar
* hide():隐藏ActionBar
*/
import android.os.Bundle;
import android.app.ActionBar;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
/**
*
* @author Android将军
*
*/
public class ActionBarTest extends Activity { private ActionBar actionBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_action_bar_test);
//获取该Activity的ActionBar
//仅仅有当应用主题没有关闭ActionBar时,该代码才干返回ActionBar
actionBar=getActionBar();
}
//为“显示ActionBar”button定义事件处理方法
public void showActionBar(View source)
{
//显示ActionBar
actionBar.show();
}
//为“隐藏ActionBar”button定义事件处理方法
public void hideActionBar(View source)
{
//隐藏ActionBar
actionBar.hide();
} }

该Activity所相应的布局文件是activity_action_bar_test,代码例如以下所看到的:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
> <Button
android:onClick="showActionBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="显示ActionBar" />
<Button
android:onClick="hideActionBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="隐藏ActionBar" /> </LinearLayout>

效果演演示样例如以下:

转载请注明出处:http://blog.csdn.net/android_jiangjun/article/details/38230733

最新文章

  1. Java高级规范之二
  2. js event 2
  3. ubuntu 安装compiz后 黑屏无法进入处理
  4. 应该如何入门deep learning呢?从UFLDL开始!
  5. firefly笔记一之http模块
  6. java实现文件编码监测(转)
  7. JDBC Connection Reset问题分析
  8. Mysql5.7忘记root密码及修改root密码的方法
  9. javascript中对象字面量与数组字面量
  10. CentOS 6.3 64位下MySQL5.1.54源码安装配置详解
  11. 网络编程之UDP编程
  12. WSL Windows Subsystem for Linux安装指南
  13. 虚拟机镜像压缩(qcow2,raw)
  14. Python2.7设置在shell脚本中自动补全功能的方法
  15. -bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory
  16. 我的2015年ccf的解答
  17. uva10003
  18. CSS宽度高度的百分比取值基于谁
  19. 方程式EQGRP_Lost_in_Translation工具之fb.py
  20. CSS中overflow:scroll怎么设置只上下滚动而不左右滚动

热门文章

  1. Laravel (5.5.33) 加载过程---make方法(四)
  2. python框架之Flask基础篇(一)
  3. ionic2 打包时报错 file-opener2
  4. python自动化测试框架(一)
  5. html——meta标签、link标签
  6. C# 设定时间内自动关闭提示框
  7. C#---EF映射MySQL
  8. 谈一谈a:link、a:visited、a:hover、a:active的正确使用顺序
  9. Linux命令(文本编辑器)
  10. enote笔记语言(4)(ver0.4)——“5w1h2k”分析法