Android - set application focus

I am trying to set the application background to a user-selected image, but I have problems. Is it possible for someone to give me an example of how to do this? I can install the ok image from my resources, but when I try to use the image on the phone, I cannot get it to work.

+4
source share
1 answer

Assuming you have created a method that allows the user to 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)); 

Remember to set the background color of the layout transparent in the XML file or you will not see the image. (this is true for everything that populates the parent window, for example, listview)

 <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" > 
+3
source

All Articles