添加设置Android应用 [英] Adding settings to android app
问题描述
这绝对是一个noob问题。我跟着指示这里 http://developer.android.com/指南/主题/ UI / settings.html#活动当我点击设置,没有任何反应和
This is definitely a noob question. I've followed the instructions here http://developer.android.com/guide/topics/ui/settings.html#Activity and when I click on settings, nothing happens.
下面是我在MainActivity.java:
Here's what I have in MainActivity.java:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
}
然后我有一个名为prefsActivity.java一个新的Java文件
Then I have a new java file called PrefsActivity.java
public class PrefsActivity extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
} }
然后,我有RES / XML / preferences.xml
Then I have res/xml/preferences.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:key="face_up"
android:title="@string/face_up"
android:summary="@string/face_up_desc"
android:defaultValue="false" />
</PreferenceScreen>
我试图使其与minsdk 7如果可能的话兼容。我缺少什么?
I am trying to make it compatible with minsdk 7 if possible. What am I missing?
推荐答案
您需要打开你的活动当你点击设置按钮。如果您使用的是操作栏,使用这样的:
You need to open your activity when you click on your settings button. If your using an action bar, use something like this:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_settings:
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
这篇关于添加设置Android应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!