• 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

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???
 
Upvote 0
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...
 
Upvote 0
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.
 
Upvote 0
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?
 
Upvote 0
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?
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones