如何在运行时更改活动中的FAB图标。我有这个代码->
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fabMainActivity);
我知道这是可以使用的,fab.setBackgroundDrawable();
但我是android的新手,不知道该怎么做。
任何帮助将不胜感激。
谢谢
更改FloatingActionButton源:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
floatingActionButton.setImageDrawable(getResources().getDrawable(R.drawable.ic_full_sad, context.getTheme()));
} else {
floatingActionButton.setImageDrawable(getResources().getDrawable(R.drawable.ic_full_sad));
}
可以用以下支持库中的代码代替:
floatingActionButton.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_full_sad));
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句