【问题标题】:AndroidX BottomAppBar navigation icon colorAndroidX BottomAppBar 导航图标颜色
【发布时间】:2019-03-09 18:39:54
【问题描述】:

我在这样的布局中定义了一个底栏:

<com.google.android.material.bottomappbar.BottomAppBar
    android:id="@+id/bottomBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    app:navigationIcon="@drawable/ic_menu_black_24dp" />

导航图标是从“新矢量可绘制”向导生成的通用图标。有没有办法给它应用色调?

底部栏不是活动操作栏。

到目前为止我已经尝试过:

  • 应用了覆盖textColorPrimary 颜色的主题
  • 应用了一个覆盖了controlColorNormal颜色的主题

如果有一个解决方案也适用于通过从 XML 加载菜单(使用 inflateMenu()replaceMenu())提供的图标,那将是完美的。

【问题讨论】:

标签: android material-design androidx material-components-android android-bottomappbar


【解决方案1】:

导航图标颜色基于colorControlNormal 属性。
您可以使用以下方法覆盖它:

<com.google.android.material.bottomappbar.BottomAppBar
    android:theme="@style/ThemeOverlay.BottomAppBar"

与:

<style name="ThemeOverlay.BottomAppBar">
    <item name="colorControlNormal">@color/....</item>
</style>

【讨论】:

    【解决方案2】:

    要以编程方式更改导航图标的颜色,请在您的活动“onCreate()”中插入此代码:

    override fun onCreate(savedInstanceState: Bundle?) {
       ...
       if (myIsLightTheme)
           bottomBar.navigationIcon?.setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP)
       else 
           bottomBar.navigationIcon?.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP)
       ...
    }
    

    【讨论】:

      猜你喜欢
      • 2016-12-20
      • 2017-01-31
      • 2020-01-24
      • 2016-12-22
      • 2015-10-23
      • 1970-01-01
      • 2017-07-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多