ToolBar 用法
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 用法的更多相关文章
- EXTJS 3.0 资料 控件之 Toolbar 两行的用法
var toolbarCarType = new Ext.Toolbar({ //width: 500, //autoWidth:true, pressed: false, toggleGroup: ...
- CoordinatorLayout、AppBarLayout、CollapsingToolbarLayout的用法,让Toolbar与系统栏融为一体
CoordinatorLayout其实是加强版的FrameLayout布局,可以监听期所有子控件的各种事件,由Design Support库提供的,能体现Material Design 的魔力.能解决 ...
- 【C#基本功 控件的用法】 Toolbar的用法
之前从事Labview编程,Labview是一门快速编程的语言,虽然快速,但作为一门语言他灵活性不够,有些方面也不是很给力,就比如 Toolbar labview就没有Toolbar的基础控件,虽然可 ...
- Android Toolbar 开发总结
初识 Toolbar Toolbar是在 Android 5.0 开始推出的一个 Material Design 风格的导航控件 ,Google 非常推荐大家使用 Toolbar 来作为Android ...
- 【Windows编程】系列第六篇:创建Toolbar与Statusbar
上一篇我们学习了解了如何使用Windows GDI画图,该应用程序都是光光的静态窗口,我们使用Windows应用程序,但凡稍微复杂一点的程序都会有工具栏和状态栏,工具栏主要用于一些快捷功能按钮.比如典 ...
- ExtJS扩展:扩展grid之toolbar button禁用表达式
在前一篇文章我们扩展了grid通过选中记录数来禁用toolbar上的按钮,有时候我们需要通过记录中的数据来决定是否禁用按钮,今天我们就来扩展它. 照例,最新的代码和例子都在gi ...
- android中的ActionBar和ToolBar
一.ToolBar 1.概述 Google在2015的IO大会上发布了系列的Material Design风格的控件.其中ToolBar是替代ActionBar的控件.由于ActionBar在各个安卓 ...
- ToolBar、ActionBar与Menu的纠葛(以及navigationIcon、setHomeButtonEnabled、setDisplayHomeAsUpEnabled)
因为贴图的繁琐...所以下面是无图版...完整的在这里: 探究一下toobar和actionbar在使用menu时的吊诡情况 一.背景介绍 toolbar最近比较火,而且是出出来代替actionbar ...
- Android下拉上滑显示与隐藏Toolbar另一种实现
public abstract class RecyclerViewScrollListener extends RecyclerView.OnScrollListener { private sta ...
随机推荐
- GitLab开发流程图示、Git命令一张图
GitLab开发流程图示.Git命令一张图 一.GitLab开发流程图示 二.Git命令一张图 作图工具:ProcessOn 一.GitLab开发流程图示 二.Git命令一张图
- Linux系统对文件及目录的权限管理(chmod、chown)
本文命令: 4 5 6 ls -l chmod chown 1.身份介绍 在linux系统中,对文件或目录来说访问者的身份有三种: ①.属主用户,拥有者(owner)文件的创建者 ②.属组用户,和文件 ...
- NodeMCU使用ArduinoJson判断指定键值对存在与否
NodeMCU使用ArduinoJson判断指定键值对存在与否 从ArduinoJson库中可以得知,判断键值对是否存在可以使用containskey()函数,但是查看ArduinoJson-cont ...
- Pytest(13)命令行参数--tb的使用
前言 pytest 使用命令行执行用例的时候,有些用例执行失败的时候,屏幕上会出现一大堆的报错内容,不方便快速查看是哪些用例失败. --tb=style 参数可以设置报错的时候回溯打印内容,可以设置参 ...
- 牛客练习赛53 E-老瞎眼pk小鲜肉(思维+线段树+离线)
前言 听说是线段树离线查询?? 做题做着做着慢慢对离线操作有点感觉了,不过也还没参透,等再做些题目再来讨论离线.在线操作. 这题赛后看代码发现有人用的树状数组,$tql$.当然能用树状数组写的线段树也 ...
- [CF套题] CF-1201
CF-1201 传送门 # = * A 500 B 1000 C 1500 D 2000 E1 2000 E2 1000 1 (2217) 1672 482 00:09 400 01:40 790 0 ...
- P3164 [CQOI2014]和谐矩阵(高斯消元 + bitset)
题意:构造一个$n*m$矩阵 使得每个元素和上下左右的xor值=0 题解:设第一行的每个元素值为未知数 可以依次得到每一行的值 然后把最后一行由题意条件 得到$m$个方程 高斯消元解一下 bitset ...
- CodeForces - 1140C
题意: 给你n首歌,每首歌有一个长度ti和一个愉悦度bi,你最多可以从中挑选出来k首歌.那么你挑选出来这首歌会为你增加sum歌愉悦度,sum的求法就是:挑选出来所有歌的长度之和,乘与挑选出来所有歌中愉 ...
- 571A Lengthening Sticks
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- C# 替换文件名的字符
https://www.cnblogs.com/lindexi/p/8970466.html