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 ...
随机推荐
- 用RabbitMQ了好几年之后,我总结出来5点RabbitMQ的使用心得
大概从 2013 年开始,我就开始了自己和 RabbitMQ 的接触,到现在已经有七年多了. 在这七年中,既有一些对 RabbitMQ 的深度体验,更有无数的血泪史. 而根据我这么多年的使用经验,我将 ...
- (一)在Spring Boot应用启动之后立刻执行一段逻辑
在Spring Boot应用启动之后立刻执行一段逻辑 1.CommandLineRunner 2.ApplicationRunner 3.传递参数 码农小胖哥:如何在Spring Boot应用启动之后 ...
- (二)SpringBoot应用运维脚本
SpringBoot应用运维脚本 一.获取PID 二.Kill命令 三.nohup命令 四.编写SpringBoot应用运维脚本 4.1全局变量 4.2编写核心方法 4.3Info方法 4.4stat ...
- Box Model 盒子模型
Box Model盒子模型,是初学者在学习HTMl5时会学到的一个重要的模型,也有一些人称它为框模型,因为盒子是属于3维,而框是平面的.称之为盒子模型,是因为其结构和盒子十分相似,其最外面是margi ...
- shell循环字符串数组
#!/bin/bash arr=("0" "1" "2" "3" "4" "5" ...
- redis防止重复提交
public interface DistributedLock { boolean getLock(String var1, String var2, int var3);//加锁 void unL ...
- 关于SANGFOR AC记录上网记录
1.查看加密APP的访问记录,不支持推送证书的方式.也就是这种的是没办法查看到的:2.查看加密网站的访问记录,通过推送证书,电脑可以查看到:手机端安卓的不能,苹果可以,但是不建议做,适用性不好:3.查 ...
- 在 .NET Core Logging中使用 Trace和TraceSource
本文介绍了在.NET Core中如何在组件设计中使用Trace和TraceSource. 在以下方面会提供一些帮助: 1.你已经为.NET Framework和.NET Core / .NET Sta ...
- k8s 调度 GPU
最近公司有项目想在 k8s 集群中运行 GPU 任务,于是研究了一下.下面是部署的步骤. 1. 首先得有一个可以运行的 k8s 集群. 集群部署参考 kubeadm安装k8s 2. 准备 GPU 节点 ...
- Pytest(5)美化插件进度条pytest-sugar
前言 在我们进行自动化测试的时候,用例往往是成百上千,执行的时间是几十分钟或者是小时级别.有时,我们在调试那么多用例的时候,不知道执行到什么程度了,而pytest-sugar插件能很好解决我们的痛点. ...