android actionbar标题栏
在android的actionBar中,actionBar的视图是固定的,左边是程序的图标和title,右边是添加的menuItem,如果想要定制actionbar中的view就要自定义视图。
首先要定义actionbar的xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="@+id/layout01"
> <ImageButton android:id="@+id/left"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="@android:color/transparent"
android:src="@drawable/show_left"
android:layout_gravity="left|center_vertical"
android:paddingLeft="8dip"
android:clickable="true"/> <TextView android:id="@+id/tv"
android:background="@android:color/transparent"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="首页"
android:textColor="@android:color/white"
android:textSize="18dip"
android:paddingTop="2dip"
android:layout_gravity="center"/> <ImageButton android:id="@+id/more"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="@android:color/transparent"
android:src="@drawable/cross"
android:paddingRight="8dip"
android:clickable="true"
android:layout_gravity="right|center_vertical"/>
</FrameLayout>
然后在onCreateMenuItem设置actionBar的样式,一定要设 置 actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM)和 actionBar.setDisplayShowCustomEnabled(true);
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu); actionBar=this.getActionBar();
ActionBar.LayoutParams params=new ActionBar.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT,Gravity.CENTER );
View view=LayoutInflater.from(this).inflate(R.layout.actionbar, null);
actionBar.setCustomView(view,params);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setDisplayShowCustomEnabled(true); ImageButton more=(ImageButton) this.findViewById(R.id.more);
ImageButton left=(ImageButton) this.findViewById(R.id.left);
left.setOnTouchListener(new MyTouchListener());
more.setOnTouchListener(new MyTouchListener());
return true; } }
class MyTouchListener implements OnTouchListener
{ @Override
public boolean onTouch(View view, MotionEvent arg1) {
if(arg1.getAction()==MotionEvent.ACTION_DOWN)
{
view.setBackgroundColor(Color.LTGRAY);
}
if(arg1.getAction()==MotionEvent.ACTION_UP)
{
view.setBackgroundColor(Color.TRANSPARENT);
}
return true;
}
android actionbar标题栏的更多相关文章
- Android应用:StatusBar状态栏、NavigationBar虚拟按键栏、ActionBar标题栏、Window屏幕内容区域等的宽高
一.屏幕中各种栏目以及屏幕的尺寸 当我们需要计算屏幕中一些元素的高度时,或许需要先获取到屏幕或者各种栏目的高度,下面这个类包含了Status bar状态栏,Navigation bar虚拟按键栏,Ac ...
- [Xamarin.Android] ActionBar Tips
[Xamarin.Android] ActionBar Tips ActionBar用途 快速搞懂 ActionBar的用途,可以参考下列文章: [Android]使用 ActionBarCompat ...
- Android ActionBar详解
Android ActionBar详解 分类: Android2014-04-30 15:23 1094人阅读 评论(0) 收藏 举报 androidActionBar 目录(?)[+] 第4 ...
- Android ActionBar(转)
本文内容 关于 ActionBar 必要条件 项目结构 环境 演示一:Action Bar 显示隐藏 演示二:Action Item 显示菜单选项 演示三:Action Home 启用“返回/向上”程 ...
- Android ActionBar应用实战,高仿微信主界面的设计
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/26365683 经过前面两篇文章的学习,我想大家对ActionBar都已经有一个相对 ...
- Android ActionBar完全解析,使用官方推荐的最佳导航栏(下) .
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/25466665 本篇文章主要内容来自于Android Doc,我翻译之后又做了些加工 ...
- Android ActionBar完全解析,使用官方推荐的最佳导航栏(上)
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/18234477 本篇文章主要内容来自于Android Doc,我翻译之后又做了些加工 ...
- [置顶]
xamarin android自定义标题栏(自定义属性、回调事件)
自定义控件的基本要求 这篇文章就当是自定义控件入门,看了几篇android关于自定义控件的文章,了解了一下,android自定义控件主要有3种方式: 自绘控件:继承View类,所展示的内容在OnDra ...
- Android ActionBar全然解析,使用官方推荐的最佳导航栏(上)
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/18234477 本篇文章主要内容来自于Android Doc.我翻译之后又做了些加工 ...
随机推荐
- 每日一“酷”之heapq
作用:heapq模块实现一个适用于Python列表的最小堆排序算法 堆(heap)是一个属性数据结构,其中子节点与父节点是一种有序关系.二叉堆是一种特殊的堆,二叉堆是完全二元树(二叉树)或者是近似完全 ...
- 新手自学ABAP(1)--数据类型
一.DATA语句 1.TYPE type ex: 可以利用冒号声明多个变量. DATA : gv_num1 TYPE I, gv_num2 TYPE I. 2.LIKE num (num可以 ...
- WPF学习笔记 控件篇 属性整理【1】FrameworkElement
最近在做WPF方面的内容,由于好多属性不太了解,经常想当然的设置,经常出现自己未意料的问题,所以感觉得梳理下. ps:先补下常用控件的类结构,免得乱了 .NET Framework 4.5 Using ...
- 命令行参数的处理函数getopt
命令参数 在linux下, shell命令的参数分两种情况: a.参数需要附加信息, 如"wget http://www.abc.com/1.zip -o 1.zip" b.参数不 ...
- 一致性hash应用到redis
理解分布式存储的本质 有一个经典的实践经验: 数(值)据大了, 什么都是问题! 如果要求128B或更大数值计算, 哪么四则运算会是个大问题! 如果要求128T或更大日志存储, 哪么文件存储会是个大问题 ...
- boost muti-thread
背景 • 今天互联网应用服务程序普遍使用多线程来提高与多客户链接时的效率:为了达到最大的吞吐量,事务服务器在单独的线程上运行服务程序: GUI应用程序将那些费时,复杂的处理以线程的形式单独 ...
- 为什么我们使用192.168.0.1作为内网ip
私有IP地址是一段保留的IP地址.只是使用在局域网中,在Internet上是不使用的. 私有IP地址的范围有: 10.0.0.0-10.255.255.255 172.16.0.0—172.31.25 ...
- wampserver修改mysql数据库密码后phpMyAdmin无法连接数据库
phpMyAdmin开始能打开,但是我在权限里把root的密码改了,再打开phpMyAdmin就显示:“phpMyAdmin 试图连接到 MySQL 服务器,但服务器拒绝连接.您应该检查 config ...
- 微软职位内部推荐-SDE2 (Windows - Audio)
微软近期Open的职位: SDE2 (Windows - Audio) Windows Partner Enablement team in Operating System Group is loo ...
- ACCESS数据库C#操作类(包含事务)
转自http://blog.csdn.net/allen3010/article/details/6336717 这个是针对ACCESS数据库操作的类,同样也是从SQLHELPER提取而来,分页程序的 ...