【发布时间】:2021-10-01 05:06:43
【问题描述】:
通过在我的 Java 类中使用此代码 navigationView.setItemIconTintList(null);,我能够将紧急图标的颜色更改为红色。我也希望能够使图标变为红色,但我似乎无法找到一种方法来做到这一点。这是picture 如您所见,图标已经是红色,但文本不是。如何将“紧急呼叫”一词从黑色更改为红色?
这是我的 Themes.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Flash" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
</style>
<style name="Theme.Flash.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="TextAppearance44">
<item name="android:textColor">@color/red</item>
</style>
<style name="Theme.Flash.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="Theme.Flash.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
这是我使用导航抽屉的 Java 类
hamburgerMenuButton = findViewById(R.id.hamburgerMenuIcon);
hamburgerMenuButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
drawerLayout.openDrawer(GravityCompat.END);
}
});
navigationView.bringToFront();
ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(Location.this, drawerLayout,
R.string.navigation_drawer_open, R.string.navigation_drawer_close);
actionBarDrawerToggle.setDrawerIndicatorEnabled(false);
drawerLayout.addDrawerListener(actionBarDrawerToggle);
actionBarDrawerToggle.syncState();
navigationView.setNavigationItemSelectedListener(Location.this);
navigationView.setItemIconTintList(null);
MenuItem menuItem = menu.findItem(R.id.emergencyCallNavigationDrawer);
SpannableString s = new SpannableString(menuItem.getTitle());
s.setSpan(new TextAppearanceSpan(this, R.style.TextAppearance44), 0, s.length(), 0);
menuItem.setTitle(s);
更新这是我的代码发生的情况
【问题讨论】:
-
检查this
标签: android android-studio android-layout