Android - Set Application Background
10,190
Assuming you have created a method to let the user choose the path to the image, use this:
// 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));
Oh Don't forget to set you Layout background color to transparent in the XML file or you won't see the image. (this is valid to anything that fills parent window like a listview, for instance)
<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"
>
Author by
PeterW
Updated on June 04, 2022Comments
-
PeterW almost 2 years
I am trying to set my applications background to a user chosen image, but I am having some trouble. Is it possible for someone to give me an example of how to do this? I can set the image ok from my resources, but when I try to use an image on the phone I can't seem to make it work.