ToolBar修改返回按钮图标

2018-12-09 22:48:14

使用Toolbar时,有时因为不同的手机设备,不能使用系统默认的主题样式或者图标,必须指定特定的资源,防止APP在不同设备上的效果不一样! 

我在使用Toolbar时,把这个布局作为一个公共的了,所以修改起来比较容易,下面是该Toolbar的布局文件:


<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:id="@+id/toolbar"

    android:layout_height="wrap_content"

    android:background="?attr/day_actionbar_bg">


    <TextView

        android:id="@+id/tv_title"

        android:layout_width="wrap_content"

        android:layout_height="match_parent"

        android:layout_gravity="center"

        android:textSize="@dimen/actionbar_txtSize"

        android:textColor="?attr/common_login_txtbg"/>

</android.support.v7.widget.Toolbar>

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

在跟节点加上这几句i就可以了:


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

        app:navigationIcon="@drawable/navigationIcon"

    android:navigationIcon="@drawable/navigationIcon"

1

2

3

就可以修改返回按钮的图标样式了, 

完整的布局代码是这样的:


<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:id="@+id/toolbar"

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

    app:navigationIcon="@drawable/navigationIcon"

    android:navigationIcon="@drawable/navigationIcon"

    android:layout_height="wrap_content"

    android:background="?attr/day_actionbar_bg">


    <TextView

        android:id="@+id/tv_title"

        android:layout_width="wrap_content"

        android:layout_height="match_parent"

        android:layout_gravity="center"

        android:textSize="@dimen/actionbar_txtSize"

        android:textColor="?attr/common_login_txtbg"/>

</android.support.v7.widget.Toolbar>

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

修改返回按钮成功!


Menu菜单文字的颜色修改:

使用ToolBar时,需要右上角的菜单按钮,菜单的文字按钮颜色也需要修改,在app的主题里修改就可以了,主题中加个:




<item name="android:actionMenuTextColor">#329da3</item>


1

2

3

4

5

但只有menu中item设置showAsAction为always的时候才有用,


  • 2021-02-03 16:43:11

    Hbase简介

    HBase是一个开源的非关系型分布式数据库,它参考了谷歌的BigTable建模,实现的编程语言为Java。它是Apache软件基金会的Hadoop项目的一部分,运行于HDFS文件系统之上,为 Hadoop 提供类似于BigTable 规模的服务。因此,它可以容错地存储海量稀疏的数据。 作者:Michaelhbjian 链接:https://www.jianshu.com/p/53864dc3f7b4 来源:简书 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

  • 2021-02-03 16:47:05

    use_framework头文件不提示

    1、之前没有用use_frameworks!添加swift库,其他库引用使用#import <xxxx.h> 2、使用use_frameworks!添加swift库后,其他库引用使用#import "xxxx.h"

  • 2021-02-03 16:52:27

    ios静态库和动态库区别

    Framework 是 Cocoa/Cocoa Touch 程序中使用的一种资源打包方式,可以将代码文件、头文件、资源文件(nib/xib、图片、国际化文本)、说明文档等集中在一起,方便开发者使用。Framework 其实是资源打包的方式,和静态库动态库的本质是没有什么关系。

  • 2021-02-03 16:57:34

    iOS中的动态库和静态库分析

    由于最近研究组件化后调试时二进制映射源码的功能,发现需要对开发中的动态库和静态库需要有一些了解。所以就有了这篇文章,由于只是了解,并没有深入到编译层面,所以本篇文章只是简单了解一些库的知识,并不深入。

  • 2021-02-03 16:58:39

    iOS静态库与动态库的区别与打包

    这篇主要是记录一下 iOS 下静态库与动态库的打包流程,以便以后用到时快速查阅,供自己也供大家学习记录。同时也简述了一下 动态库 与 静态库 的区别。

  • 2021-02-03 16:59:59

    iOS 静态库和动态库全分析

    库就是程序代码的集合,将 N 个文件组织起来,是共享程序代码的一种方式。从本质上来说是一种可执行代码的二进制格式,可以被载入内存中执行。

  • 2021-02-03 17:01:30

    iOS库 .a与.framework区别

    静态库:连接时完整地拷贝至可执行文件中,被屡次使用就有多份冗余拷贝。 动态库:连接时不复制,程序运行时由系统动态加载到内存,供程序调用,系统只加载一次,多个程序共用,节省内存。

  • 2021-02-03 17:13:58

    iOS - 封装静态库

    静态库:链接时完整的拷贝至可执行文件中,被多次使用就有多份冗余拷贝,.a的静态库 .framework的静态库