【问题标题】:Android Wear - Action Drawer Icon ColorAndroid Wear - 动作抽屉图标颜色
【发布时间】:2017-07-25 00:30:17
【问题描述】:

我正在使用带有菜单的操作抽屉。图标显示为黑色,如下图所示:

我正在尝试更改这些图标的颜色,与设计指南中的几乎相同:

但是,我找不到在哪里执行此操作或哪个样式属性允许我执行此操作。

【问题讨论】:

  • 不要认为这是可能的。您是否尝试过更改整个图标?
  • 我什至在 xml 中更改了图标本身的颜色(它是一个可绘制的矢量)。什么都没有

标签: wear-os action-drawer


【解决方案1】:

如果您使用的是CircledImageView,您可以使用setImageTint(int tint) 直接在视图上设置图标的色调。

如果你使用的是传统的 ImageView,你需要从你的图标资源中创建一个 Drawable 并为其应用颜色,然后将其设置到视图中:

Drawable iconDrawable = mContext.getResources().getDrawable(R.drawable.icon, mContext.getTheme());
iconDrawable.setTint(mContext.getColor(R.color.bg_color, mContext.getTheme()));
iconView.setImageDrawable(iconDrawable);

编辑:要访问菜单中的图标,您可以在创建菜单时执行以下操作:

for(int i = 0; i < menu.size(); i++) {
    Drawable iconDrawable = menu.getItem(i).getIcon();
    iconDrawable.setTint(mContext.getColor(R.color.bg_color, mContext.getTheme()));
}

【讨论】:

  • 这是一个菜单,不是自定义视图。它是从菜单 xml 加载的。
  • 更新了我的答案。如果这仍然没有帮助,请发布一些代码,显示您的菜单 XML 的外观以及您如何在代码中创建它。
【解决方案2】:

他们更改了 Action Drawer 项目的布局,但没有提供更改颜色/禁用它的选项。

v23/action_drawer_item_view.xml

<ImageView
        android:id="@+id/wearable_support_action_drawer_item_icon"
        android:layout_width="@dimen/action_drawer_item_icon_size"
        android:layout_height="@dimen/action_drawer_item_icon_size"
        android:layout_gravity="center_vertical"
        android:background="@drawable/action_item_icon_background"
        **android:tint="?android:attr/colorBackground"**
        android:padding="@dimen/action_drawer_item_icon_padding"
        android:scaleType="fitCenter"
        tools:ignore="ContentDescription" />

由于无法访问适配器,因此无法更改颜色。

【讨论】:

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