ToolBar修改返回按钮图标

使用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>

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

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

就可以修改返回按钮的图标样式了,
完整的布局代码是这样的:

<?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>

修改返回按钮成功!

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



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

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

posted @   brave-sailor  阅读(540)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
历史上的今天:
2016-03-22 Swift Explore - 关于 Swift 中的 isEqual 的一点探索
2016-03-22 iOS-BLE蓝牙开发持续更新
点击右上角即可分享
微信分享提示