gpt4 book ai didi

Android:无法更改后退箭头导航图标的颜色

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:44:06 24 4
gpt4 key购买 nike

我正在使用新的 android appcompat 工具栏。我需要为汉堡图标和后退箭头图标设置相同的自定义颜色。使用 drawerArrowStyle 允许我更改汉堡图标而不是箭头。这个问题只出现在 Lollipop 设备上,任何 Lollipop 之前的设备都可以。

Burger

Arrow

代码如下:

工具栏:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="@color/my_primary"
local:theme="@style/My.Toolbar"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

样式.xml:

<style name="Theme.Base" parent="Theme.AppCompat.Light">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">@color/my_primary</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">@color/black</item>
</style>

<style name="My.Theme" parent="Theme.Base">
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>

<style name="My.Toolbar" parent="Theme.AppCompat.NoActionBar">
<!-- color of the title text in the Toolbar, in the Theme.AppCompat theme: -->
<item name="android:textColorPrimary">@color/my_actionbartext</item>

<!-- necessary to support older Android versions.-->
<item name="actionMenuTextColor">@color/my_actionbartext</item>

<item name="android:textColorSecondary">@color/my_actionbartext</item>
</style>

<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="color">@color/my_actionbartext</item>
</style>

我试过使用来自 here 的解决方案但它没有用。有人有什么想法吗?

最佳答案

只需在您的 Activity/Fragment 中执行此操作:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
getSupportActionBar().setHomeAsUpIndicator(getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha, null));
else
getSupportActionBar().setHomeAsUpIndicator(getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha));

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

关于Android:无法更改后退箭头导航图标的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28706887/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com