[Android Pro] Toolbar的完全自定义
reference to : http://blog.csdn.net/elder_sword/article/details/46634751
Toolbar是什么,不知道的可以去大神的博客瞻仰下 
http://blog.csdn.net/lmj623565791/article/details/45303349 
我当时也是看这篇学习的,但是怎么说,看完之后想在自己的项目中把Toolbar完全自定义的时候,博客中并没有讲解。这篇博客也只是一个记载,并没有很高深的技术,废话不多说。
我自己项目中的样子 
下面的布局里你就可以随便写你的Toolbar了。注意下面在设置title等属性的时候要用app命名空间,android打头的也有,但是可能设置不会显示 
toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:segmentedgroup="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:navigationIcon="@drawable/press_back"
app:title=" " >
<TextView
android:id="@+id/toolbar_num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="16dp"
android:text="num"
android:textColor="#fff"
android:visibility="gone"
android:textSize="16dp" />
<com.hs.diskmanager.view.SegmentedGroup
android:id="@+id/toolbar_segment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:orientation="horizontal"
segmentedgroup:border_width="1dp"
segmentedgroup:checked_text_color="#ff33b5e5"
segmentedgroup:corner_radius="10dp"
segmentedgroup:tint_color="@android:color/white" > <RadioButton
android:id="@+id/toolbar_phone"
style="@style/RadioButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="One" /> <RadioButton
android:id="@+id/toolbar_udisk"
style="@style/RadioButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Two" />
</com.hs.diskmanager.view.SegmentedGroup> <TextView
android:id="@+id/toolbar_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="16dp"
android:text="编辑"
android:textColor="#fff"
android:textSize="16dp" /> </android.support.v7.widget.Toolbar>
对应布局引用
<RelativeLayout 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" > <include layout="@layout/toolbar" android:id="@+id/id_toolbar"/>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/id_toolbar">
</FrameLayout>
</RelativeLayout>
可能有点人用完会发现自己下面的布局盖在Toolbar的布局上了,解决方法上面也有写到,就是below,其它不再多说.
[Android Pro] Toolbar的完全自定义的更多相关文章
- Android线程管理之ThreadPoolExecutor自定义线程池
		前言: 上篇主要介绍了使用线程池的好处以及ExecutorService接口,然后学习了通过Executors工厂类生成满足不同需求的简单线程池,但是有时候我们需要相对复杂的线程池的时候就需要我们自己 ... 
- Android下添加新的自定义键值和按键处理流程
		Android下添加新的自定义键值和按键处理流程 说出来不怕大家笑话,我写这篇博客的原因在于前几天去一个小公司面试Android系统工程师,然后在面试的时候对方的技术总监问了我 ... 
- android:ToolBar详解
		android:ToolBar详解(手把手教程) 泡在网上的日子 发表于 2014-11-18 12:49 第 124857 次阅读 ToolBar 42 来源 http://blog.mosil.b ... 
- Android中使用ListView绘制自定义表格(2)
		上回再写了<Android中使用ListView绘制自定义表格>后,很多人留言代码不全和没有数据样例.但因为项目原因,没法把源码全部贴上来.近两天,抽空简化了一下,做了一个例子. 效果图如 ... 
- 【Android Training UI】创建自定义Views(Lesson 1 - 创建一个View类)
		发布在我的网站 http://kesenhoo.github.io/blog/2013/06/30/android-training-ui-creating-custom-views-lesson-1 ... 
- Android图表库MPAndroidChart(五)——自定义MarkerView实现选中高亮
		Android图表库MPAndroidChart(五)--自定义MarkerView实现选中高亮 在学习本课程之前我建议先把我之前的博客看完,这样对整体的流程有一个大致的了解 Android图表库MP ... 
- 强烈推荐:Android史上最强大的自定义任务软件Tasker
		强烈推荐:Android史上最强大的自定义任务软件Taskerhttp://bbs.mumayi.com/thread-28387-1-1.html(出处: 木蚂蚁手机乐园) Android上的Tas ... 
- Android调用系统相机、自定义相机、处理大图片
		Android调用系统相机和自定义相机实例 本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显示出来,该例子也会涉及到Android加载大图片时候的处理 ... 
- Android下添加新的自定义键值和按键处理流程【转】
		本文转载自: Android下添加新的自定义键值和按键处理流程 说出来不怕大家笑话,我写这篇博客的原因在于前几天去一个小公司面试Android系统工程师,然后在面试的时候对方的技术总监问了我一 ... 
随机推荐
- 【bzoj2435】[NOI2011]道路修建
			题目描述 在 W 星球上有 n 个国家.为了各自国家的经济发展,他们决定在各个国家之间建设双向道路使得国家之间连通.但是每个国家的国王都很吝啬,他们只愿意修建恰好 n – 1条双向道路. 每条道路的修 ... 
- 关于hibernate链接数据源的配置参数详细解释(转)
			具体使用方法还可以参考以下地址: http://blog.csdn.net/xb12369/article/details/41517409 以下信息转自: http://baike.baidu.co ... 
- 关系型数据库ACID
			关系型数据库ACID 一.事务 定义:所谓事务,它是一个操作序列,这些操作要么都执行,要么都不执行,它是一个不可分割的工作单位. 准备工作:为了说明事务的ACID原理,我们使用银行账户及资金管理的案例 ... 
- ZipArchive 打包下载压缩包
			用php的header()方式下载压缩包. 要点:1.不能在header导出压缩包前向浏览器输出内容,否则文件下载压缩包成功,打开的压缩包也会显示被破坏. 2.在压缩文件包的php代码前不可以有js脚 ... 
- mysql常用语句总结
			1.创建语句 CREATE DATABASE database_name //创建数据库 //删表 DROP TABLE IF EXISTS `t_social_user_extend`; //建表C ... 
- YC大牛的判题任务-想法
			YC大牛的判题任务 Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld Java class ... 
- iOS开发初级课程
			iOS开发初级课程 针对学员 掌握Objective C,C或者C++,有语言基础的学员,想从事iOS开发工作. iOS开发那些事-了解iOS开发(8集) 在课程中,我们首先介绍如何使用nib和故事 ... 
- $.extend()了解心得
			2.1 extend(result,item1,item2-..) 这里这个方法主要用来合并,将所有的参数项都合并result中,并返回result,但是这 样就会破坏result的结构. 2.2 e ... 
- class training
			实验3-1 分别使用while循环.do while循环.for循环求 (即求1+2+3+ --+100). 参考: 源码 方法一#include<stdio.h> int main(){ ... 
- 线段树基础模板&&扫描线
			线段树的单点更新+区间求和 hdu1166敌兵布阵 Input 第一行一个整数T,表示有T组数据. 每组数据第一行一个正整数N(N<=),表示敌人有N个工兵营地 ,接下来有N个正整数,第i个正整 ... 
