• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Set a background image in a PreferenceScreen

Leolicos

Member
I would like to set my own background in my preference screen, but the method I know doesn't work...

RelativeLayout
ImageView
PreferenceScreen

This just crashes my app.
 
I've looked into this more, and I guess the doc says I need to use a style, but that doesn't seem to work either. Here's my styles.xml

<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="prefVerticalTheme">
<item name="android:windowBackground">@drawable/backvert</item>
</style>
<style name="prefHorizontalTheme">
<item name="android:windowBackground">@drawable/backhorz</item>
</style>
</resources>

then in my preferenceactivity.onCreate

int orientation = getRequestedOrientation();
if ( orientation == Configuration.ORIENTATION_PORTRAIT )
setTheme(R.style.prefVerticalTheme);
else
setTheme(R.style.prefHorizontalTheme);

addPreferencesFromResource(R.xml.preferences);

That doesn't seem to work either. How do I set the background image to a preference page???
 
All you have to do is in your layout file for the pref screen, set the android:background property of the parent layout view to the drawable you want.
 
what do you mean by parent layout?

Here's what I have.

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/background">
</PreferenceScreen>

then in code I simply

addPreferencesFromResource(R.xml.preferences);

that still doesn't set the background to my image...
 
what do you mean by parent layout?

Here's what I have.

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/background">
</PreferenceScreen>

then in code I simply

addPreferencesFromResource(R.xml.preferences);

that still doesn't set the background to my image...


Err... Sorry, I wasn't aware that PreferenceScreen was a pre-defined XML tag.

Well, in that case, the only thing i can think of would be to wrap the <PreferenceScreen></PreferenceScreen> in a LinearLayout and set the android:background property to your background.
 
That just crashed the app...

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/background">
<PreferenceScreen>
</PreferenceScreen>
</LinearLayout>

Does it make a different that my class extends a PreferenceActivity, not a regular activity?
 
That just crashed the app...

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/background">
<PreferenceScreen>
</PreferenceScreen>
</LinearLayout>

Does it make a different that my class extends a PreferenceActivity, not a regular activity?

I am honestly not sure. I have never messed with PreferenceScreens. Is it just a predefined preference activity? If so, why not just make your own?
 
How would I do what the PreferenceScreen does? I looked up the ListView and all that, but then I found that it's much easier to just do a PreferenceActivity and use a PreferenceScreen. How do I do it without a PreferenceActivity?
 
Is there a tutorial handy to set up a ListView in the same way a PreferenceScreen works but not use a PreferenceActivity and a PreferenceScreen?
 
Back
Top Bottom