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 ...
随机推荐
- iPhone新建项目不能全屏
上个周做项目的时候,发现新建了一个项目不能全屏.伤透了我的脑筋,然后又请教了团队里其他两个大牛帮我搞定了这个问题. 虽然是搞定了,但也看的出大牛也是云里雾里.歪打正着解决的. 今天又想新做个项目,这个 ...
- kindeditor编辑器获取不到修改后的新文本
在编辑文章的功能中,文章内容使用了kindeditor编辑器进行处理,但是修改文本后保存时发现获取到的内容还是修改前的文本内容. 引用编辑器的标签: <textarea id="txt ...
- PHP error_reporting
E_ERROR 致命错误,脚本执行中断,就是脚本中有不可识别的东西出现 E_WARNING 部分代码出错,但不影响整体运行 E_PARSE 字符.变量或结束的地方写规范有误 ...
- 《R语言实战》读书笔记--第三章 图形初阶(二)
3.4添加文本.自定义坐标轴和图例 很多作图函数可以设置坐标轴和文本标注.比如标题.副标题.坐标轴标签.坐标轴范围等.需要注意的是并不是所有的绘图函数都有上述的参数,需要进行验证.可以将一些默认的参数 ...
- Linux命令之rhn_check
NAME rhn_check - check for queued actions on RHN and execute them SYNOPSIS /usr/sbin/rhn_check [-v] ...
- Velocity模版使用
<!-- https://mvnrepository.com/artifact/org.apache.velocity/velocity --> <dependency> &l ...
- js获取url参数,操作url参数
function getParam(key) { var tmp = location.search; tmp = decodeURIComponent(tmp); var index = tmp.i ...
- vue实现tab切换
需要弄类似tab切换的功能就是一个点击切换上一页下一页的页面 找到这个获得灵感 <!DOCTYPE html> <html lang="en"> <h ...
- centos编译安装vim并支持lua
系统环境:centos6.5 x86 (basic server) 1.安装编译环境. # yum groupinstall "Development Tools" 2.安装vim ...
- MongoDB中$redact操作符的使用
介绍 redact <- redaction 修订/校验,意思是对文档内容进行过滤,选择一些过滤或保留的信息 . access level 存取等级 有三种: - $$DESCEND 返回当前等 ...