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 ...
随机推荐
- C#学习笔记----静态字段和静态方法
1.使用关键字 static 修饰的字段或方法成为静态字段和静态方法,如 public static int num = 1;2.静态字段属于类,并为类所用.而非静态字段属于对象,只能被特定的对象专有 ...
- hdu 2492 树状数组 Ping pong
欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Ping pong Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 3 ...
- 【Android】Android中期项目设计题目-界面设计小作业-提交截止时间2016.4.8
评选三份作品,请发关于app运行界面截图的博客.
- 基于eclipse创建maven工程
一.创建项目 1.Eclipse中用Maven创建项目 上图中Next 2.继续Next 3.选maven-archetype-webapp后,next 4.填写相应的信息,Packaged是默认创建 ...
- 怎么用SecureCRT这个工具把linux服务器的压缩文件下载到本地的一个路径。
依次按上图中所示的突变,进入sftp的命令界面.输入help命令:即:sftp>help得到如下的截图. 比较重要的命令有:cd----查询服务器端的路径 lcd---查询本地的地址 pwd:服 ...
- 7月9日day1总结
今天的学习过程和小结 上午学习了前端包括html,CSS,js等基本内容 前端10.25.134.187 html js css 1.块元素 ---默认占满整行,如果设置了高度和宽度都有效,如果不设置 ...
- 阿里云服务器ubuntu安装java运行环境
服务器 阿里云服务器ubuntu安装java运行环境 转:http://www.codingyun.com/article/45.html 今天来给大家介绍一下在阿里云ubuntu服务器下安装java ...
- 寻宝游戏(bzoj 3991)
Description 小B最近正在玩一个寻宝游戏,这个游戏的地图中有N个村庄和N-1条道路,并且任何两个村庄之间有且仅有一条路径可达.游戏开始时,玩家可以任意选择一个村庄,瞬间转移到这个村庄,然后可 ...
- 让Vs2010支持 Css3+HTML5
第一步. 先到微软官方下载一个 Microsoft Visual Studio 2010 sp1 . 给传送门:.microsoft.com/downloads/zh-cn/details.aspx? ...
- 搜索水题四连发_C++
特别声明:以下题目有部分为原创题,涉及版权问题,不得转载,违者追究 法律责任! 话说这是一套神题,只有你想不到,没有你做不到 题目更正后比 Pascal 跑得还快哈~ 一道特别裸,但是特别坑的搜索题 ...