嘿,我正在尝试在我的操作栏中设置 homeindicator,但看起来箭头是白色的/p>
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_baseline_arrow_back_24)
我使用的主题
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<item name="android:textColorSecondary">@android:color/black</item>
<item name="android:statusBarColor" tools:targetApi="l">@color/bar_color</item>
<item name="colorPrimary">@color/splashscreen_text_color</item>
<item name="colorOnPrimary">@color/black</item>
<item name="itemBackground">@color/black</item>
<item name="actionOverflowButtonStyle">@style/actionOverflowButtonStyle</item>
<item name="homeAsUpIndicator">@drawable/ic_baseline_arrow_back_24</item>
</style>
<style name="actionOverflowButtonStyle" parent="@style/Widget.AppCompat.ActionButton.Overflow">
<item name="android:tint">@color/black</item>
</style>
我得到的结果 Result
我期待的是: the expected result
箭头绘制文件
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="@color/black">
<path
android:fillColor="@android:color/black"
android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z"/>
</vector>
答案 0 :(得分:0)
easy 是在活动文件中定义图像视图和
imageView.setColorFilter(Color.argb(0, 0, 0, 0));
技术观点 --> how to set tint for imageview
答案 1 :(得分:0)
在您的“应用主题”中添加名为“drawerArrowStyle”的项目并创建它的样式:
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- your style here... -->
<item name="drawerArrowStyle">@style/backArrowTheme</item>
</style>
<style name="backArrowTheme" parent="AppTheme">
<!-- your arrow color: -->
<item name="android:textColorSecondary">@color/black</item>
<!-- your app bar bgc: -->
<item name="android:background">@color/white</item>
</style>
添加文件 - app_bar_main.xml:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="MissingConstraints">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="@+id/toolBar"
android:fitsSystemWindows="true"
android:theme="@style/backArrowTheme"/>
</com.google.android.material.appbar.AppBarLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
然后将此文件包含在您的主 xml 文件中
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
并在您的主 Java 文件中设置:
Toolbar toolbar = findViewById(R.id.toolBar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);