Android setting LinearLayout background programmatically

后端 未结 6 888
一整个雨季
一整个雨季 2021-02-06 02:34

I have a situation where I need to set a background on a LinearLayout programatically.

In my layout, I am setting my background using `android:background=\"?android:att

6条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-06 03:23

    Please try the following code.

    LinearLayout layout=(LinearLayout) findViewById(R.id.layoutImage);
    layout.setBackgroundResource(R.drawable.bg);
    

提交回复
热议问题