Get background color of a Layout

后端 未结 5 1172
醉梦人生
醉梦人生 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-05 13:02

    To get background color of a Layout:

    LinearLayout lay = (LinearLayout) findViewById(R.id.lay1);
    ColorDrawable viewColor = (ColorDrawable) lay.getBackground();
    int colorId = viewColor.getColor();
    

    If It is RelativeLayout then just find its id and use there object instead of LinearLayout.

提交回复
热议问题