简体   繁体   English

如何在较旧的 Android 设备(即 Gingerbread 和 Froyo)上显示首选项屏幕?

[英]How can I show a preferences screen on older Android devices i.e. Gingerbread and Froyo?

I need to show a preferences screen from my application.我需要从我的应用程序中显示首选项屏幕。 I've managed to implement this and it works on Ice-Cream Sandwich and newer devices but doesn't work on older devices like Gingebread and Froyo.我设法实现了这一点,它适用于冰淇淋三明治和更新的设备,但不适用于 Gingebread 和 Froyo 等旧设备。 I'm using ActionBarSherlock as a compatibility library to support older devices.我使用 ActionBarSherlock 作为兼容库来支持旧设备。

Here's the code for the Activity that contains the preference screen:这是包含首选项屏幕的Activity的代码:

public class Settings extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);    
        getFragmentManager().beginTransaction()
                .replace(android.R.id.content, new Preferences())
                .commit();
    }

}

This is the sample code from my activity that invokes the preferences screen:这是我的活动中调用首选项屏幕的示例代码:

public class Trend extends SherlockActivity {

    @Override
    public boolean onOptionsItemSelected(MenuItem itmMenuitem) {
        if (itmMenuitem.getItemId() == R.id.search) {
            startActivity(new Intent(getBaseContext(), Settings.class));
            return true;
        }
    }

}

When users try and open the preferences screen on older devices, I get an exception that reads:当用户尝试在旧设备上打开首选项屏幕时,我收到一条异常消息:

java.lang.NoSuchMethodError: com.mridang.stupidapp.Settings.getFragmentManager
at com.mridang.stupidapp.Settings.onCreate(Settings.java:15)

How should I modify my preferences screen to work with older devices ie API 8?我应该如何修改我的首选项屏幕以使用旧设备,即 API 8? Thanks.谢谢。

Neither ActionBarSherlock nor the Android Support Library provides support for Preference Fragments. ActionBarSherlock 和Android 支持库都不提供对首选项片段的支持。

You need to revert to Perference Activities as explained in the Settings Documentation .您需要按照 设置文档中的说明恢复到 Preference 活动。

There are a few old questions that discuss the same topic:有几个老问题讨论同一主题:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何在Android的“偏好设置”中添加一些文本(即某种“关于”信息) - How can i add some text (i.e. kind of “about” info) in Preferences in Android 迁移到旧版Android Studio(即3.1.2)上的androidx? - Migrate to androidx on older version of android studio i.e. 3.1.2? 如何在 android 2.2.2 (Froyo) 中使用 BitmapRegionDecoder 代码? - How can I use BitmapRegionDecoder code in android 2.2.2 (Froyo)? 如何在Android中触发闹钟,即播放闹钟铃声? - How can I set off an alarm i.e. play an alarm tone in Android? Android Studio 中的 WebView 无法正确显示网站(即 www.google.com 没有徽标、搜索栏和屏幕上方的所有内容) - WebView in Android Studio does not show sites properly (i.e. www.google.com is without logo, search bar and all the stuff on upper screen) 如何从无线和网络列表中删除“蓝牙”(Android姜饼) - how can i remove “Bluetooth ” from the list of wireless & networks (Android Gingerbread) 如何确保我要使用的端口始终可用(即未使用)? - How can I make sure that the port I want to use is always available (i.e. not in use)? 如何在 android 的另一个屏幕上显示过滤后的数据? - How can i show my filtered data on another screen in android? 如何在GingerBread 2.3.3中导入.so文件? - How can i import .so file in GingerBread 2.3.3? 如何等到 HttpServer 完成(即加入其后台线程)? - How can I wait until a HttpServer has finished (i.e. join its background thread)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM