Android - toolbar navigation 样式
1.修改title 边距
修改边距使用系统的app属性来引入使用,即:
xmlns:app="http://schemas.android.com/apk/res-auto"
- 1
比如:
<android.support.v7.widget.Toolbar
xmlns: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.Toolbar
android: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.Toolbar
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"
style="@style/mToolbarStyle"/>
- 1
上面的方法,在有些机子上会失效,大家有上面办法,请告诉我,谢谢!
5.参考
Android - toolbar navigation 样式的更多相关文章
- Android Toolbar样式定制详解
前言 Marterial Design出来也有一段时间了,为了紧跟Google的设计规范,决定在项目中使用Toolbar.使用了一段时间之后,发现很多时候原始的Toolbar并不能满足项目的要求.为了 ...
- Android ToolBar
众所周知,在使用ActionBar的时候,一堆的问题:这个文字能不能定制,位置能不能改变,图标的间距怎么控制神马的,由此暴露出了ActionBar设计的不灵活.为此官方提供了ToolBar,并且提供了 ...
- [置顶]
xamarin android toolbar(踩坑完全入门详解)
网上关于toolbar的教程有很多,很多新手,在使用toolbar的时候踩坑实在太多了,不好好总结一下,实在浪费.如果你想学习toolbar,你肯定会去去搜索androd toolbar,既然你能看到 ...
- Android - Bottom Navigation View
目录 Android - Bottom Navigation View Android - Bottom Navigation View Overview 一直以来,关于Android的底部导航的功能 ...
- ANDROID – TOOLBAR STEP BY STEP(转)
今年(2014) 的 Google I/O 發表令多數人為之一亮的 Material Design,而 Google 也從「Google I/O 2014」 開始,大家也陸陸續續地看到其更新的 And ...
- Android RatingBar 自定义样式
Android RatingBar 自定义样式 1.先定义Style: <style name="RadingStyle" parent="@android:sty ...
- android中的样式和主题
有的时候我们一个页面要用很多个textview,而且这些textview的样式非常相像,这种情况下我们可以把这些样式抽取出来,然后在每个textview中引用即可,这样修改起来也方便. 我们来看一个简 ...
- xamarin android checkbox自定义样式
xamarin android checkbox自定义样式 在drawable文件在新建checkbox_bg.xml文件 <?xml version="1.0" encod ...
- Android开发工程师文集-Fragment,适配器,轮播图,ScrollView,Gallery 图片浏览器,Android常用布局样式
Android开发工程师文集-Fragment,适配器,轮播图,ScrollView,Gallery 图片浏览器,Android常用布局样式 Fragment FragmentManager frag ...
随机推荐
- Linux自学系列 -- 常用指令的使用
1.查看目录下内容>ls //列出目录下的文件信息>ls -l //以“详细信息"查看目录文件>ls -a //查看目录“全部”(包括隐藏文件)文件> ...
- 【bzoj4562】[Haoi2016]食物链 拓扑排序+dp
原文地址:http://www.cnblogs.com/GXZlegend/p/6832118.html 题目描述 如图所示为某生态系统的食物网示意图,据图回答第1小题 现在给你n个物种和m条能量流动 ...
- 如何在CentOS7上改变网络接口名
如何在CentOS7上改变网络接口名 传统上,Linux的网络接口被枚举为eth[0123...],但这些名称并不一定符合实际的硬件插槽,PCI位置,USB接口数量等,这引入了一个不可预知的命名问题( ...
- 交叉编译VIM并移植到ARM嵌入式Linux系统
原创作品,允许转载,转载时请务必以超链接形式标明文章.作者信息和本声明,否则将追究法律责任. 众所周知,vim是vi的增强版本,实际体验要比vi好用很多,由于笔者为ARM系统制作的基于busybo ...
- SQL的主键和外键的作用
SQL的主键和外键约束 转载自:http://www.cnblogs.com/ywb-lv/archive/2012/03/12/2391860.html感谢原文作者的总结 SQL的主键和外键的作用: ...
- AngularJS中获取ng-repeat动态生成的ng-model值
需求:通过ng-repeat动态生成的CheckBox,实现勾选控制对应的批次号.如图: html: <div class="clearfix"> <div cl ...
- php格式化时间
1.Y 年份的四位数 2.m 月份的数字(01-12) 3.d 一个月中的第几天(01-31) 4.w 星期几的数字表示(0-6) 5.H 24小时制(00-23) 6.i 分(00-59) 7.s ...
- XML格式化及解析
XML格式化工具:notepad++ 下载地址 http://rj.baidu.com/soft/detail/13478.html?ald 一个教程地址:http://jingyan.ba ...
- php命名空间与可变函数
命名空间一个最明确的目的就是解决重名问题,PHP中不允许两个函数或者类出现相同的名字,否则会产生一个致命的错误.这种情况下只要避免命名重复就可以解决 对于命名空间,官方文档已经说得很详细[查看],我在 ...
- Winform 模拟Session
背景 在Web中Session的功能很好用,于是想Winform中实现该功能,典型应用场景则是登陆成功后,当一段时间不操作,则该会话过期,提示重新登陆. 资源下载 测试代码 示例说明:登陆进去10s不 ...