Get background color of a Layout

后端 未结 5 1168
醉梦人生
醉梦人生 2020-12-05 12:34

I want to find the background color of a Layout from my code. Is there any way to find it? something like linearLayout.getBackgroundColor()?

5条回答
  •  悲哀的现实
    2020-12-05 13:14

    This can only be accomplished in API 11+ if your background is a solid color.

    int color = Color.TRANSPARENT;
    Drawable background = view.getBackground();
    if (background instanceof ColorDrawable)
        color = ((ColorDrawable) background).getColor();
    

提交回复
热议问题