开发者

Changing background colour of an Activity based on a theme/style

I have an Activity which has a style resource set in the manifest (using android:theme="@style/blah". I wish to dynamically change the background colour of this Ac开发者_StackOverflow社区tivity in Java code. How would I go about doing this?

Thanks!


<?xml version="1.0" encoding="utf-8"?>
<FrameLayout    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:id="@+id/activityRootContainer>

</FrameLayout>

Then in your code:

findViewById(R.id.activityRootContainer).setBackgroundDrawable(getResources().getDrawable(R.drawable.backgroundImage))

or

findViewById(R.id.activityRootContainer).setBackgroundColor(Color.RED)

HTH?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜