【问题标题】:Android ActionBar logo doesn't displayAndroid ActionBar 徽标不显示
【发布时间】: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(使用简单的标题应该可以)

标签: android android-actionbar


【解决方案1】:

新的兼容库在工具栏(以前的操作栏)中不使用徽标或应用程序图标。您应该查看样式指南:https://www.google.com/design/spec/layout/structure.html#structure-toolbars

从棒棒糖开始,您将获得新功能,例如在此屏幕上为通知栏着色:

一个很酷的新功能是着色,它可以根据您的品牌需要为所有 ui 元素着色。

【讨论】:

    【解决方案2】:

    最好使用android.support.v7.widget.Toolbar,您可以如下设置应用的操作栏:

    Toolbar toolbar = (Toolbar) findViewById(R.id.apptoolbar);
    setSupportActionBar(toolbar);
    toolbar.setNavigationIcon(R.drawable.your_app_logo);
    

    更多信息你可以阅读Structure Of App Bar(被称为ActionBar)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-26
      相关资源
      最近更新 更多