如何着色菜单图标已经覆盖了几次,例如: Android上的工具栏图标着色
除此解决方案外,还存在导航图标的问题.将主题(叠加)应用于工具栏只会对文本和白名单图标进行着色(请参阅:https://stackoverflow.com/a/26817918/2417724)
如果您设置了一个自定义图标(这种情况非常简单,如果您不想显示默认的后退箭头,则需要更改它),则此自定义图标不会显示.
那你如何处理你的图标?我的所有图标都是默认的黑色,我不想在工具栏中使用特殊的白色版本.
我有一个可选择的Button/ImageView的可绘制资源,如下所示:
<selector>
<item android:state_selected="true">
<layer-list>
<item>
<shape android:shape="oval">
<solid android:color="@color/blue"/>
</shape>
</item>
<item>
<bitmap
android:src="@drawable/ic_icon"
android:tint="@color/white"/>
</item>
</layer-list>
</item>
<item>
<layer-list>
<item>
<shape android:shape="oval">
<solid android:color="@color/background_unselected"/>
</shape>
</item>
<item>
<bitmap
android:src="@drawable/ic_icon"
android:tint="@color/icon_unselected"/>
</item>
</layer-list>
</item>
Run Code Online (Sandbox Code Playgroud)
因为我已切换到使用VectorDrawables,上述声明不起作用,因为我无法引用带<bitmap>
标记的VectorDrawable .但据我所知,这是我可以给图标着色的唯一方法.
我也不能在代码中应用Colorfilter,因为这会使整个drawable而不仅仅是图标.
有什么建议?
我想定义一个替代的按钮样式,它使用我的 secondaryColor 作为背景,并?colorOnSecondary
分别用于文本。
但是我很难在样式中定义 textColor 。MaterialButton 正在为使用?colorOnPrimary
. 因此,重写很麻烦。
有没有另一种方法可以在没有 selectorDrawable 的情况下设置颜色?
android android-button material-components material-components-android
Compose 中有没有一种方法可以在不使用 的情况下将可组合项与居中项目对齐ConstraintLayout
?
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically,
) {
Spacer(Modifier.weight(1f))
Button(...)
Label(Modifier.weight(1f),...)
}
Run Code Online (Sandbox Code Playgroud)
问题是我显示Label
有条件地显示,如果我隐藏带有权重的两个元素,按钮会稍微移动。
也不确定使用权重是否会比ConstraintLayout
一开始对性能产生更大的影响。