1.修改title 边距

修改边距使用系统的app属性来引入使用,即:

  xmlns:app="http://schemas.android.com/apk/res-auto"
  • 1

比如:

<android.support.v7.widget.Toolbarxmlns:app="http://schemas.android.com/apk/res-auto"android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="1dp" android:background="?attr/colorPrimary" android:minHeight="?attr/actionBarSize" android:orientation="vertical" app:contentInsetLeft="10dp"/>

当然也可以在style.xml中修改,自己研究吧;


2.修改navigation icon的padding值

修改padding值,就需要在style.xml中修改;在此我们修改的是navigation的pading值:

Widget.AppCompat.Toolbar.Button.Navigation

比如:

1.定义style

    <style name="myToolbarNavigationButtonStyle" parent="@style/Widget.AppCompat.Toolbar.Button.Navigation"> <item name="android:minWidth">0dp</item> <item name="android:padding">@dimen/margin_horizontal_large</item> <item name="android:scaleType">centerInside</item> </style>
  • 1

2.app主题中应用

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="toolbarNavigationButtonStyle">@style/myToolbarNavigationButtonStyle</item> </style>
  • 1

3.title居中

toolbar是可以自定义布局的,可以在toolbar中添加一个textview来实现,从而代替title;
比如:

1.布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbarandroid:id="@+id/toolbar" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" ​ android:layout_height="?actionBarSize" android:background="@null" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" app:theme="@style/AppTheme"> <TextView android:id="@+id/toolbar_title" style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"/> </android.support.v7.widget.Toolbar>

2.初始化

View v = findViewById(R.id.toolbar);
if (v != null) {toolbar = (Toolbar) v;setSupportActionBar(toolbar);toolbarTitle = (TextView) v.findViewById(R.id.toolbar_title);if (toolbarTitle != null) {getSupportActionBar().setDisplayShowTitleEnabled(false); } }

3.使用
设置title两种方式:
(1)直接在setText();
(2)在AndroidManifest.xml中指定title;
(3)如果有baseActivity的话,解决如下:
Activity有一个onTitleChanged的接口,在Activity的onPostCreate与setTitle中都会调用这个方法;

protected void onPostCreate(@Nullable Bundle savedInstanceState) {if (!isChild()) {mTitleReady = true; onTitleChanged(getTitle(), getTitleColor()); } mCalled = true; }

所以只需要在BaseActivity中重载这个方法就行了,如下所示 :

@Override
protected void onTitleChanged(CharSequence title, int color) { super.onTitleChanged(title, color); if (toolbarTitle != null) { toolbarTitle.setText(title); } }

参考资料 - 点我


4.修改menu的padding值

定义style值:

    <style name="mToolbarStyle" parent="@style/Widget.AppCompat.Toolbar"><item name="android:paddingRight">0dp</item> <item name="android:paddingLeft">13dp</item> </style>
  • 1

使用:

<android.support.v7.widget.Toolbarandroid:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="1dp" android:background="?attr/colorPrimary" android:minHeight="?attr/actionBarSize" android:orientation="vertical" style="@style/mToolbarStyle"/>
  • 1

上面的方法,在有些机子上会失效,大家有上面办法,请告诉我,谢谢!


5.参考

修改toolbar的一些属性
toolbar学习使用

Android - toolbar navigation 样式相关推荐

  1. Android Toolbar样式定制详解

    前言 Marterial Design出来也有一段时间了,为了紧跟Google的设计规范,决定在项目中使用Toolbar.使用了一段时间之后,发现很多时候原始的Toolbar并不能满足项目的要求.为了 ...

  2. 安卓APP_ 控件(7)——Toolbar栏目样式

    摘自:安卓APP_ 控件(7)--Toolbar栏目样式 作者:丶PURSUING 发布时间: 2021-04-02 15:42:07 网址:https://blog.csdn.net/weixin_ ...

  3. android toolbar控件,Android Toolbar控件

    1. Toolbar类 Toolbar是替代ActionBar的产物,低版本可以使用v7兼容包,使用Theme.AppCompat主题,并添加配置. false true 2. Toolbar配置 主 ...

  4. Android Toolbar 居中

    Android Toolbar封装 1.QToolbar是什么 标题栏控件,基于Toolbar控件封装 有返回按钮 左标题 居中标题 子标题 右侧菜单 优势: 继承于Toolbar,Toolbar的A ...

  5. Android Jetpack Navigation 深入体验报告

    Android Jetpack 之 Navigation深入体验报告 前言 当前Android开发中使用Fragment来开发页面已经成为主流做法.Fragment轻量.可控性强等优点让人感觉很香. ...

  6. android 自定义 黑点,Android自定义密码样式 黑点转换成特殊字符

    本文为大家分享了Android自定义密码样式的制作代码,黑点换成¥.%等特殊字符,供大家参考,具体内容如下 复制下面代码即可: 布局: xmlns:android="http://schem ...

  7. uber_像Uber这样的Android Google地图样式

    uber Have you ever noticed how Uber and other few popular location-based applications have a differe ...

  8. Android自定义按钮样式

    安卓系统自带的按钮样式很不好看,满足不了感官需求,如何自定义一个自己需要的按钮样式呢? 分三步来介绍: 1.自定义按钮背景样式,在res/drawable/目录下新建bg_btn.xml文件. < ...

  9. Android Toolbar设置向上箭头,标题等

    Android Toolbar设置向上箭头,标题等 标签: android布局 2016-07-25 22:58 1163人阅读 评论(0) 收藏 举报 版权声明:本文为博主原创文章,未经博主允许不得 ...

最新文章

  1. but no declaration can be found for element #39;aop:aspectj-autoproxy#39;.
  2. 对移码满足二进制减法的小思考
  3. HTML DOM console.table() 方法
  4. 《Hack与HHVM权威指南》——1.1 为什么使用类型检查器
  5. 3种方法快速制作tpk文件
  6. android 的mvp架构,老生常谈Android的MVP架构
  7. gdt描述_GDT形位公差详解.ppt
  8. CE找基址及偏移教程 外挂必学
  9. c语言编八卦图形,关于C语言实现一个八卦图!(我代码写好了,求人改动一下)
  10. 亲属关系--并查集训练T1
  11. OSChina 周日乱弹 ——领导问:功能几天能开发完?怎么回
  12. Excel不用函数嵌套一键完成四舍六入五成双
  13. 5和6 objbc oracle_《Oracle Database 12c完全参考手册(第7版)(试读版)》
  14. 在Ubuntu上安装VM WarePlayer 编译不过
  15. java河南口腔医疗机构线上服务系统计算机毕业设计MyBatis+系统+LW文档+源码+调试部署
  16. 用python做自动化控制-用 Python 自动化办公能做到哪些有趣或有用的事情?
  17. 推荐几个堪称教科书级别的 Android 音视频入门项目
  18. 制造业企业招工难,怎么从根本上解决?
  19. 查询订单表中同一父订单下的所有子订单(蜜芽)
  20. 博客园积分与排名升级攻略 //转

热门文章

  1. Oracle常用dump命令
  2. verycd重整——linux教程
  3. 下划线转驼峰,并且首字母大写
  4. 模型可解释性-树结构可视化
  5. 将Numpy加速700倍——CuPy
  6. 机器学习基础专题:线性判别器
  7. adminlte+layui框架搭建3 - layui弹出层
  8. 硬件——STM32,GPIO篇
  9. 分步骤学习自动化测试
  10. Oracle删除表主键语句