[英]How do I set the background of an Activity with code?
我目前正在使用XML布局來設置我的活動背景。 我怎樣才能在Java代碼中執行此操作?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg" >
在調用Activity.setContentView(View)
之前,請在主View
上使用setBackground...()
方法之一。
將id屬性設置為父RelativeLayout。 比在活動代碼中通過id找到它並使用setBackgroundResource方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.