Android 有没有办法为MaterialButton';设置MotionLayout自定义属性;什么是IContit?
据此, CustomAttribute是使用attributeName指定的,attributeName需要匹配对象的getter/setter方法,以便: getter:getName(例如getBackgroundColor) setter:setName(例如setBackgroundColor) (因此Android 有没有办法为MaterialButton';设置MotionLayout自定义属性;什么是IContit?,android,android-motionlayout,materialbutton,constraintset,Android,Android Motionlayout,Materialbutton,Constraintset,据此, CustomAttribute是使用attributeName指定的,attributeName需要匹配对象的getter/setter方法,以便: getter:getName(例如getBackgroundColor) setter:setName(例如setBackgroundColor) (因此motion:attributeName需要是backgroundColor) 我试过使用material按钮使用下面的属性名称,但都不起作用 “IContentResource”、“I
motion:attributeName
需要是backgroundColor
)
我试过使用material按钮使用下面的属性名称,但都不起作用
“IContentResource”、“IContentResource”、“IconTint”、“IconTint”、“ColorFilter”
有什么建议吗
这些就是我得到的错误
E/TransitionLayout:com.google.android.material.button.MaterialButton上找不到自定义属性“IconTint”
E/TransitionLayout:com.google.android.material.button.MaterialButton必须具有方法setIContent
E/TransitionLayout:no method seticonton View“f\u editor\u image\u View\u terminal”
MotionLayout的CustomAttribute使用反射来设置视图上的值(大致基于Java beans约定)
所以如果你说
<CustomAttribute motion:attributeName="foo" motion:customColorValue="@color/keyTextColor" />
这将适用于MotionLayout。这将在动画期间创建许多对象,但它们的寿命很短
class MyButton extends MaterialButton {
public MyButton(@NonNull Context context) {
super(context);
}
public MyButton(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public MyButton(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
void setIconTint(int color) {
ColorStateList colorStateList = new ColorStateList(new int[1][0],new int[]{color});
setIconTint(colorStateList);
}
}