【发布时间】:2019-03-07 22:31:13
【问题描述】:
在运行时单击时,我需要更改FloatingActionButton 的背景颜色。
我的代码:
public static void setButtonTint(FloatingActionButton button, ColorStateList tint) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) {
((TintableBackgroundView) button).setSupportBackgroundTintList(tint);
} else {
ViewCompat.setBackgroundTintList(button, tint);
}
}
public void switchFABmode(){
switch (floatingActionButtonMode){
case 0:
setButtonTint(shareFAB,getResources().getColorStateList(R.color.colorGrey));
setButtonTint(deleteFAB,getResources().getColorStateList(R.color.colorPrimary));
floatingActionButtonMode = 1;
Toast.makeText(this, "Tap time to delete",Toast.LENGTH_SHORT).show();
break;
case 1:
shareFAB.setBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimary));
deleteFAB.setBackgroundColor(ContextCompat.getColor(this, R.color.colorGrey));
Toast.makeText(this,"Tap time to share", Toast.LENGTH_SHORT).show();
floatingActionButtonMode = 0;
break;
}
}
没有做到这一点。有人可以指出我的错误,或提供解决方案吗?
【问题讨论】:
-
效果不佳:(
-
请在此处发布完整的代码 sn-p。
-
编辑了我的帖子...
标签: java android floating-action-button