【发布时间】:2015-12-03 04:20:05
【问题描述】:
我为我的 ActionBar 实现了一个主题:
<style name="MyTheme"
parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
<item name="android:background">@color/actionbar_background</item>
<item name="android:displayOptions">useLogo|showHome</item>
<item name="android:logo">@mipmap/ic_launcher</item>
<item name="logo">@mipmap/ic_launcher</item>
<item name="background">@color/actionbar_background</item>
</style>
我在AndroidManifest.xml中应用了它:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/MyTheme">
...
我知道我的主题在我看到颜色变化时有效,但是我的操作栏图标从未出现。我只有在我的活动的onCreate 方法中明确调用此代码时才能看到它:
ActionBar actionBar = getSupportActionBar();
actionBar.setLogo(R.mipmap.ic_launcher);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
我觉得为每个活动复制粘贴相同的代码是不正确的。请帮我解决这个问题。
【问题讨论】:
-
你在使用棒棒糖吗?
-
@Johan 是的,没错
-
好吧,棒棒糖(阅读材料)不会在
ActionBar/Toolbar中显示图标,这是他们设计指南的一部分。 -
你应该检查这个:stackoverflow.com/a/8729587/3743245顺便说一句,尝试使用图标(setIcon)...徽标不适合 Material Design(使用简单的标题应该可以)