4
我試圖將我的應用程序背景設置爲用戶選擇的圖像,但我遇到了一些麻煩。有人可以給我一個如何做到這一點的例子嗎?我可以從我的資源中設置圖像,但是當我嘗試在手機上使用圖像時,我似乎無法使其工作。Android - 設置應用程序背景
我試圖將我的應用程序背景設置爲用戶選擇的圖像,但我遇到了一些麻煩。有人可以給我一個如何做到這一點的例子嗎?我可以從我的資源中設置圖像,但是當我嘗試在手機上使用圖像時,我似乎無法使其工作。Android - 設置應用程序背景
假設你已經創建了讓用戶選擇的路徑圖像的方法,使用此:
// Variable with the path to the background
String bg_path = "/sdcard/bg/background.png" // <-- This path can be whatever you like
//Change background of Activity
getWindow().setBackgroundDrawable(Drawable.createFromPath(bg_path));
哦,不要忘了佈局設置背景顏色爲你透明的XML文件中,或者你將無法看到圖像。 (例如,對於像列表視圖那樣填充父窗口的任何東西都是有效的)
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout="@+id/m_layout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android.background="Color.TRANSPARENT"
>