[英]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.