xml中的设置:

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorAccent"
app:navigationIcon="@drawable/ic_back_white_24dp"
app:title="标题"
app:titleTextColor="@color/white">
</android.support.v7.widget.Toolbar>

如果你不在xml中设置参数的话,代码中的设置:

 1 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
2 toolbar.setTitle("标题");
3 toolbar.setTitleTextColor(Color.WHITE);
4 toolbar.setNavigationIcon(R.drawable.ic_back_white_24dp);
5
6 //点击左边返回按钮监听事件
7 toolbar.setNavigationOnClickListener(new View.OnClickListener() {
8 @Override
9 public void onClick(View v) {
10
11 }
12 });

全面但包括不太常用的用法

xml中的配置:

<!--   navigationIcon  左边返回箭头图标
navigationContentDescription 目前还不知道其作用
titleMarginStart 标题距离(开始)左边的距离
-->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorAccent"
app:logo="@mipmap/ic_launcher"
app:navigationContentDescription=""
app:navigationIcon="@drawable/ic_back_white_24dp"
app:subtitle="子标题"
app:subtitleTextColor="@color/white"
app:title="标题"
app:titleMarginStart="90dp"
app:titleTextColor="@color/white">

如果你想修改主标题和子标题的文字大小,你可通过如下方式:
首先定义一个style:

<!--主标题-->
<style name="ToolbarTitle" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textColor">#f0f0</item>
<item name="android:textSize">15sp</item>
</style> <!--子标题-->
<style name="ToolbarSubtitle" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Subtitle">
<item name="android:textColor">#f0f0</item>
<item name="android:textSize">10sp</item>
</style>

然后:

<!-- app:titleTextAppearance="@style/ToolbarTitle"-->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorAccent"
app:logo="@mipmap/ic_launcher"
app:navigationContentDescription=""
app:navigationIcon="@drawable/ic_back_white_24dp"
app:subtitle="子标题"
app:subtitleTextColor="@color/white"
app:title="标题"
app:titleMarginStart="90dp"
app:titleTextAppearance="@style/ToolbarTitle"
app:titleTextColor="@color/white">

其它的不抄啦,原博见:https://www.jianshu.com/p/103fa0c7e7f3

ToolBar 用法的更多相关文章

  1. EXTJS 3.0 资料 控件之 Toolbar 两行的用法

    var toolbarCarType = new Ext.Toolbar({ //width: 500, //autoWidth:true, pressed: false, toggleGroup: ...

  2. CoordinatorLayout、AppBarLayout、CollapsingToolbarLayout的用法,让Toolbar与系统栏融为一体

    CoordinatorLayout其实是加强版的FrameLayout布局,可以监听期所有子控件的各种事件,由Design Support库提供的,能体现Material Design 的魔力.能解决 ...

  3. 【C#基本功 控件的用法】 Toolbar的用法

    之前从事Labview编程,Labview是一门快速编程的语言,虽然快速,但作为一门语言他灵活性不够,有些方面也不是很给力,就比如 Toolbar labview就没有Toolbar的基础控件,虽然可 ...

  4. Android Toolbar 开发总结

    初识 Toolbar Toolbar是在 Android 5.0 开始推出的一个 Material Design 风格的导航控件 ,Google 非常推荐大家使用 Toolbar 来作为Android ...

  5. 【Windows编程】系列第六篇:创建Toolbar与Statusbar

    上一篇我们学习了解了如何使用Windows GDI画图,该应用程序都是光光的静态窗口,我们使用Windows应用程序,但凡稍微复杂一点的程序都会有工具栏和状态栏,工具栏主要用于一些快捷功能按钮.比如典 ...

  6. ExtJS扩展:扩展grid之toolbar button禁用表达式

          在前一篇文章我们扩展了grid通过选中记录数来禁用toolbar上的按钮,有时候我们需要通过记录中的数据来决定是否禁用按钮,今天我们就来扩展它.       照例,最新的代码和例子都在gi ...

  7. android中的ActionBar和ToolBar

    一.ToolBar 1.概述 Google在2015的IO大会上发布了系列的Material Design风格的控件.其中ToolBar是替代ActionBar的控件.由于ActionBar在各个安卓 ...

  8. ToolBar、ActionBar与Menu的纠葛(以及navigationIcon、setHomeButtonEnabled、setDisplayHomeAsUpEnabled)

    因为贴图的繁琐...所以下面是无图版...完整的在这里: 探究一下toobar和actionbar在使用menu时的吊诡情况 一.背景介绍 toolbar最近比较火,而且是出出来代替actionbar ...

  9. Android下拉上滑显示与隐藏Toolbar另一种实现

    public abstract class RecyclerViewScrollListener extends RecyclerView.OnScrollListener { private sta ...

随机推荐

  1. JavaWeb——Cookie,Session学习汇总

    什么是Cookie Cookie的作用 安全性能 Cookie的语法 Cookie注意细节 Cookie实例练习 什么是会话Session Session语法 Session与浏览器窗口的关系 ses ...

  2. ubuntu下scala下载+集成IDEA开发环境

    环境须知: ubuntu 16.04 scala 2.11.0 jdk 1.8.0 Idea 2016.3 JDK环境安装 (1)安装jdk, 注意scala很好的支持jdk 1.8 的jvm 编译环 ...

  3. Spring Boot项目application.yml文件数据库配置密码加密

    在Spring boot开发中,需要在application.yml文件里配置数据库的连接信息,或者在启动时传入数据库密码,如果不加密,传明文,数据库就直接暴露了,相当于"裸奔"了 ...

  4. Spring boot AOP 记录请求日志

    如何将所有的通过url的请求参数以及返回结果都输出到日志中? 如果在controller的类中每个方法名都写一个log输出肯定是不明智的选择. 使用spring的AOP功能即可完成. 1. 在pom. ...

  5. 给jekyll博客添加搜索功能

    使用SWIFTYPE为jekyll博客添加搜索引擎 步骤 1.首先去swiftype注册一个账号 2.接着添加自己想要配置的网站地址并为新设定的引擎添加一个名字(非会员只能设置一个引擎). 3.收到验 ...

  6. Qt update刷新之源码分析(一)

    在做GUI开发时,要让控件刷新,会调用update函数:那么在调用了update函数后,Qt究竟基于什么原理.执行了什么代码使得屏幕上有变化?本文就带大家来探究探究其内部源码. Qt手册中关于QWid ...

  7. 2019牛客多校 Round9

    Solved:3 Rank:181 H Cutting Bamboos 这个东西好像叫整体二分 #include <bits/stdc++.h> using namespace std; ...

  8. Codeforces Round #660 (Div. 2) A. Captain Flint and Crew Recruitment、Captain Flint and a Long Voyage

    题目链接:Captain Flint and Crew Recruitment 题意: t组输入,每一组输入一个n.这里我们说一下题目定义的近似质数概念: "如果可以将正整数x表示为p⋅q, ...

  9. UVA442 矩阵链乘 Matrix Chain Multiplication

    题意: 这道题也是在不改变原序列每个元素位置的前提下,看每个元素与他身边的两个元素那个先结合能得到最大的能量 题解: 很明显这是一道区间dp的题目,这道题要断环成链,这道题需要考虑在这个区间上某个元素 ...

  10. Baby-step giant-step算法

    写在前面: 学习笔记,方便复习,学习资料来自网络,注明出处 我们都在努力奔跑,我们都是追梦人 结论 In group theory, a branch of mathematics, the baby ...