Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PreferenceActivity works properly on Android 2.1, but not 4.1 (padded)

I'm writing an application. It needs to run on old android OS's to be useful. I have written the preferences screen using a PreferencesActivity that populates with a options.xml file that contains PreferenceScreen. It has no submenu for preferences (so PreferenceFragment provides no real benefits).

In Android 2.1 (2.2 and 2.3, haven't tested on ICS yet) the screen displays properly like so in landscape: Eclair

But on Jellybean, it looks like this: Jellybean

It looks terrible. I have nothing defined as a layout, just standard addPreferencesFromResource(). Does anyone know what the cause of this might be? Or a solution?

My onCreate looks like this:

    protected void onCreate(Bundle savedInstanceState) { //
    super.onCreate(savedInstanceState);
    Log.i(TAG, "Options Activity Loaded.");
    setTitle(getString(R.string.optionsTitle));
    addPreferencesFromResource(R.xml.options);
    setupListeners();
}

Everything else just makes Preference objects and assigns methods to do stuff when they get clicked. I don't want to make code for both PreferenceFragment and PreferenceActivity. I do not understand how google expects us to use Fragment APIs if the largest version marketshare doesn't have that API and they will not add it to the compatibility lib.

like image 642
Mgamerz Avatar asked Nov 13 '22 21:11

Mgamerz


1 Answers

Your application can support both the old and the new functionality for SharedPreferences. You can provide a Class for the old preferences and a Class for the new. Its not much more code. You can make your app backward compatible like this:

Class spc = Build.VERSION_SDK_INT < Build.VERSION_CODES.HONEYCOMB ? 
    oldPreferenceActivity.class : newFragmentPreferenceActivity.class;

Intent i = new Intent (this, spc);
startActivityForResult (i, SHOW_PREFERENCES); 
like image 77
CocoNess Avatar answered Nov 15 '22 12:11

CocoNess