在我的代码的一部分中,我有以下代码:
linearLayout.setBackgroundColor(Color.RED);
在另一部分中,我想获取设置的背景色,例如:
linearLayout.getBackgroundColor();
但是没有这样的方法,只有这样的方法:
Drawable drawable = linearLayout.getBackground();
如何获得可绘制对象的颜色?(我不想扩展LinearLayout并手动存储背景色等。)
试试这个:
((ColorDrawable)linearLayout.getBackground()).getColor();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句