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的完全自定义的更多相关文章

  1. Android线程管理之ThreadPoolExecutor自定义线程池

    前言: 上篇主要介绍了使用线程池的好处以及ExecutorService接口,然后学习了通过Executors工厂类生成满足不同需求的简单线程池,但是有时候我们需要相对复杂的线程池的时候就需要我们自己 ...

  2. Android下添加新的自定义键值和按键处理流程

            Android下添加新的自定义键值和按键处理流程     说出来不怕大家笑话,我写这篇博客的原因在于前几天去一个小公司面试Android系统工程师,然后在面试的时候对方的技术总监问了我 ...

  3. android:ToolBar详解

    android:ToolBar详解(手把手教程) 泡在网上的日子 发表于 2014-11-18 12:49 第 124857 次阅读 ToolBar 42 来源 http://blog.mosil.b ...

  4. Android中使用ListView绘制自定义表格(2)

    上回再写了<Android中使用ListView绘制自定义表格>后,很多人留言代码不全和没有数据样例.但因为项目原因,没法把源码全部贴上来.近两天,抽空简化了一下,做了一个例子. 效果图如 ...

  5. 【Android Training UI】创建自定义Views(Lesson 1 - 创建一个View类)

    发布在我的网站 http://kesenhoo.github.io/blog/2013/06/30/android-training-ui-creating-custom-views-lesson-1 ...

  6. Android图表库MPAndroidChart(五)——自定义MarkerView实现选中高亮

    Android图表库MPAndroidChart(五)--自定义MarkerView实现选中高亮 在学习本课程之前我建议先把我之前的博客看完,这样对整体的流程有一个大致的了解 Android图表库MP ...

  7. 强烈推荐:Android史上最强大的自定义任务软件Tasker

    强烈推荐:Android史上最强大的自定义任务软件Taskerhttp://bbs.mumayi.com/thread-28387-1-1.html(出处: 木蚂蚁手机乐园) Android上的Tas ...

  8. Android调用系统相机、自定义相机、处理大图片

    Android调用系统相机和自定义相机实例 本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显示出来,该例子也会涉及到Android加载大图片时候的处理 ...

  9. Android下添加新的自定义键值和按键处理流程【转】

    本文转载自: Android下添加新的自定义键值和按键处理流程     说出来不怕大家笑话,我写这篇博客的原因在于前几天去一个小公司面试Android系统工程师,然后在面试的时候对方的技术总监问了我一 ...

随机推荐

  1. CPU核数跟多线程的关系

    一直以来有这样的疑惑,单核CPU适合多线程吗?是不是几个核的CPU开几个线程是最合适的? 今天就这一问题查了一些资料,现整理如下: 要说多线程就离不开进程,进程和线程的区别在这里就不详细说了,只将关键 ...

  2. HDu1003(maxn sum)

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABBcAAAMDCAYAAAD5XP0yAAAgAElEQVR4nOy97a8c133n2X+H3xjIC4

  3. Unity手游之路<十一>资源打包Assetbundle

    http://blog.csdn.net/janeky/article/details/17652021 在手游的运营过程中,更新资源是比不可少的.资源管理第一步是资源打包.传统的打包可以将所有物件制 ...

  4. Android 异步消息处理机制解析

    Android 中的异步消息处理主要由四个部分组成,Message.Handler.MessageQueue.Looper.下面将会对这四个部分进行一下简要的介绍. 1. Message: Messa ...

  5. Android实用代码模块集锦

    1. 精确获取屏幕尺寸(例如:3.5.4.0.5.0寸屏幕) 1 2 3 4 5 6 public static double getScreenPhysicalSize(Activity ctx)  ...

  6. leetcode:32 最长有效括号

     题目: 给一个包含了'(' 和 ')'的字符串,求出其中最长有效括号的长度. 做题情况:自己做出来,但做了较长的时间. 思路:可以算得穷举法的时间复杂度为O(n^3).虽然这题求的是最长的长度,但是 ...

  7. PHP常用字符串操作函数实例总结(trim、nl2br、addcslashes、uudecode、md5等)

    /*常用的字符串输出函数 * * echo() 输出字符串 * print() 输出一个或多个字符串 * die() 输出一条信息,并退出当前脚本 * printf() 输出格式化字符串 * spri ...

  8. 【Networking】go get 失败,代理配置

    推荐VPN: https://vpnso.com/   如果还是有问题,比如: 重新编译Git,使用openssl替换gnutls,方法如下: http://askubuntu.com/questio ...

  9. MVC RadioButton

    本文介绍如何创建radiobutton. Step 1: 创建一个类用于获取所有的选项. public class Company { public string SelectedDepartment ...

  10. js apply 和 call

    http://www.cnblogs.com/KeenLeung/archive/2012/11/19/2778229.html