preferenceActivity正常运行在Android 2.1,而不是4.1(填充) [英] PreferenceActivity works properly on Android 2.1, but not 4.1 (padded)

查看:169
本文介绍了preferenceActivity正常运行在Android 2.1,而不是4.1(填充)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写的应用程序。它需要对旧Android操作系统的运行是有益的。我已经使用preferencesActivity与包含preferenceScreen一个options.xml文件填充写的preferences屏幕。它有preferences没有子菜单(所以preferenceFragment提供没有真正的好处)。

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).

在Android 2.1的横向(2.2和2.3,也没有对ICS测试还),屏幕显示正常,像这样:

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

但在杰利贝恩,它看起来像这样:

But on Jellybean, it looks like this:

这看起来很可怕。我定义为布局没什么,只是标准的附加preferencesFromResource()。有谁知道这样做的原因可能是什么呢?还是一个解决方案?

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?

我的onCreate看起来是这样的:

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();
}

其他的一切只是让preference对象和分配方法做的东西获得点击,当他们。我不想做code为preferenceFragment和preferenceActivity。我不明白谷歌如何期望我们使用的API片段如果最大版本的市场份额不具有API,他们不会把它添加到兼容性库。

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.

推荐答案

您的应用程序可以同时支持老的共享preferences新功能。您可以为老preferences一个类和新的一类。它不是更code。你可以让你的应用程序这样的向后兼容:

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); 

这篇关于preferenceActivity正常运行在Android 2.1,而不是4.1(填充)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆