ActionBar 图标和文字颜色不同
ActionBar icon and text different colors
我想制作一个操作栏,但后退指示器和文本必须使用不同的颜色。我怎样才能做到这一点?
当我使用这个时:
getSupportActionBar().setHomeAsUpIndicator(ContextCompat.getDrawable(getApplicationContext(), R.drawable.back));
它变得很奇怪:
在此处输入图片描述
[2
我用的图片是这样的:
您可以将图像用作后退按钮:
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeAsUpIndicator(getDrawable(R.drawable.back))
您在主题背景中更改了标题文字颜色
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primaryDark</item>
<item name="colorAccent">@color/highlightRed</item>
<item name="actionBarTheme">@style/ToolbarStyle</item>
</style>
<style name="ToolbarStyle" parent="Widget.AppCompat.ActionBar">
<item name="android:textColorPrimary">@color/white</item>
</style>
尝试下面的代码,将此代码放入 activity 的 onCreate()
中:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(Html.fromHtml("<font color='#ffff00'>Your Title</font>"));
getSupportActionBar().setHomeAsUpIndicator(getDrawable(R.drawable.back_button));
如果您遇到 getSupportActionBar()
的问题,请使用 getActionBar()
或者,您可以创建自定义工具栏来实现此目的:
看看这个: Android toolbar center title and custom font
要解决图像问题,您可以访问以下网站:
从该站点下载任何背景图像并将所有 5 张不同尺寸的图像放入 android 工作室的 mipmap/drawable 文件夹中。 https://materialdesignicons.com/
或者,使用此站点将您的图像转换为 5 种不同尺寸:
romannurik.github.io
我想制作一个操作栏,但后退指示器和文本必须使用不同的颜色。我怎样才能做到这一点?
当我使用这个时:
getSupportActionBar().setHomeAsUpIndicator(ContextCompat.getDrawable(getApplicationContext(), R.drawable.back));
它变得很奇怪: 在此处输入图片描述
[
我用的图片是这样的:
您可以将图像用作后退按钮:
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeAsUpIndicator(getDrawable(R.drawable.back))
您在主题背景中更改了标题文字颜色
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primaryDark</item>
<item name="colorAccent">@color/highlightRed</item>
<item name="actionBarTheme">@style/ToolbarStyle</item>
</style>
<style name="ToolbarStyle" parent="Widget.AppCompat.ActionBar">
<item name="android:textColorPrimary">@color/white</item>
</style>
尝试下面的代码,将此代码放入 activity 的 onCreate()
中:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(Html.fromHtml("<font color='#ffff00'>Your Title</font>"));
getSupportActionBar().setHomeAsUpIndicator(getDrawable(R.drawable.back_button));
如果您遇到 getSupportActionBar()
的问题,请使用 getActionBar()
或者,您可以创建自定义工具栏来实现此目的:
看看这个: Android toolbar center title and custom font
要解决图像问题,您可以访问以下网站:
从该站点下载任何背景图像并将所有 5 张不同尺寸的图像放入 android 工作室的 mipmap/drawable 文件夹中。 https://materialdesignicons.com/
或者,使用此站点将您的图像转换为 5 种不同尺寸: romannurik.github.io