开发者

How do adjust the background property of top layout

开发者 https://www.devze.com 2023-04-01 22:44 出处:网络
I have a linearLayout as the main layout in my android x开发者_如何学运维ml file. The background is set to \"@drawable/window_background_red\". Inside the activity (at run time) I want to set this to

I have a linearLayout as the main layout in my android x开发者_如何学运维ml file. The background is set to "@drawable/window_background_red". Inside the activity (at run time) I want to set this to "@drawable/window_background_green".

window_background_green.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <gradient
                android:type="linear"
                android:startColor="#000000"
                android:endColor="#004400"
                android:angle="-90"
                />
        </shape>
    </item>
</selector>


let's say that for linearLayout android:id="@+id/linearLayout" then in code:

LinearLayout linearLayout = (LinearLayout)findViewById(R.id.linearLayout);

linearLayout.setBackgroundResource(R.drawable.window_background_green);

And there, you've set the background to be @drawable/window_background_green

0

精彩评论

暂无评论...
验证码 换一张
取 消