【发布时间】:2017-07-25 00:30:17
【问题描述】:
【问题讨论】:
-
不要认为这是可能的。您是否尝试过更改整个图标?
-
我什至在 xml 中更改了图标本身的颜色(它是一个可绘制的矢量)。什么都没有
标签: wear-os action-drawer
【问题讨论】:
标签: wear-os action-drawer
如果您使用的是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()));
}
【讨论】:
他们更改了 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" />
由于无法访问适配器,因此无法更改颜色。
【讨论】: