gpt4 book ai didi

android - 如何在新 Material 主题中更改工具栏主页图标(后退箭头)颜色?

转载 作者:行者123 更新时间:2023-11-29 17:20:24 25 4
gpt4 key购买 nike

我一一尝试了链接上的所有内容,如

How to change color of the back arrow in the new material theme?

How to change Toolbar home icon color

Change toolbar back arrow color

How to change change text and arrow color on Toolbar?

Android: unable to change color of back arrow navigation icon

等等,

但对我来说没有任何用处。

我的布局xml代码,

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
style="@style/MyCustomTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
style="@style/MyCustomTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:minHeight="?attr/actionBarSize"
app:tabMaxWidth="0dp" />

在 styles.xml 中

<style name="MyCustomTabLayout" parent="Theme.AppCompat.Light">
<item name="tabIndicatorHeight">2dp</item>
<item name="tabPaddingStart">12dp</item>
<item name="android:layout_width">match_parent</item>
<item name="tabPaddingEnd">12dp</item>
<item name="tabBackground">@drawable/background_tab_item</item>
<item name="tabIndicatorColor">@color/jd_yellow</item>
<item name="android:layout_gravity">center</item>
<item name="android:gravity">center</item>
<item name="tabSelectedTextColor">@color/jd_white</item>
<item name="tabTextAppearance">@style/MyCustomTabTextAppearance</item>
<item name="android:textAppearance">@style/MyCustomTabTextAppearance</item>
<item name="android:background">@drawable/background_tab_item</item>
<item name="android:textColorSecondary">@color/jd_white</item>
<item name="colorControlNormal">@color/jd_white</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<item name="actionBarTheme">@style/MyApp.ActionBarTheme</item>
<item name="actionBarWidgetTheme">@style/WidgetStyle</item>
<item name="colorPrimary">@color/jd_white</item>
<item name="colorPrimaryDark">@color/jd_white</item>
<item name="android:textColorPrimary">@color/jd_white</item>
</style>

<style name="WidgetStyle" parent="style/ThemeOverlay.AppCompat.Light">
<item name="colorControlNormal">@color/jd_white</item>
</style>

<style name="MyApp.ActionBarTheme" parent="@style/ThemeOverlay.AppCompat.ActionBar">
<!-- change color the arrow or three lines -->
<item name="colorControlNormal">@color/jd_white</item>
</style>

<!-- Style for the navigation drawer icon -->
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">@color/jd_white</item>
</style>

<style name="MyCustomTabTextAppearance" parent="TextAppearance.Design.Tab">
<item name="android:textColor">@color/jd_white</item>
<item name="android:textSize">@dimen/tab_layout_text_size</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_gravity">center</item>
<item name="android:gravity">center</item>
</style>

还尝试将下面添加到 onCreate()

  Drawable upArrow = ContextCompat.getDrawable(mContext, R.drawable.abc_ic_ab_back_material);
upArrow.setColorFilter(ContextCompat.getColor(mContext, R.color.white), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(upArrow);

没有任何作用,它的颜色仍然是黑色,我做错了什么??请帮忙。

最佳答案

非常简单,这对我有用:

    <android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="@color/PrimaryColor"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:elevation="4dp" />

关于android - 如何在新 Material 主题中更改工具栏主页图标(后退箭头)颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36867923/

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