如果我的计算机通过互联网在线并且工作正常,我有一点开发让我知道。问题是,我注意到我的首选项输入框没有启用键盘建议。建议在模拟器上工作,但不在我的galaxy s7边缘。
这是首选项活动的XML代码:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="@string/settingsHeader">
<EditTextPreference
android:key="ip"
android:title="@string/ip"
android:summary="@string/ipsummary"
android:defaultValue="192.168.1.1"
android:id="@+id/ip"/>
<EditTextPreference
android:key="port"
android:title="@string/port"
android:summary="@string/portsummary"
android:defaultValue="23"
android:id="@+id/port"/>
</PreferenceCategory>
</PreferenceScreen>
,这是活动的java文件:
公共类MyPreferenceActivity扩展了PreferenceActivity {
private final static String TAG = "SettingsAcitivity";
private EditText ip;
private EditText port;
public static Context context;
public MyPreferenceActivity() {
context = this;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit();
ip = (EditText) findViewById(R.id.ip);
port = (EditText) findViewById(R.id.port);
// ip.setInputType(InputType.TYPE_CLASS_TEXT);
//port.setInputType(InputType.TYPE_CLASS_TEXT);
}
public static class MyPreferenceFragment extends PreferenceFragment {
private final static String TAG = "MyPreferenceFragment";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.fragment_preference);
findPreference("ip").setOnPreferenceChangeListener(
new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Toast.makeText(context,toastMessage(context.getResources().getString(R.string.ipUpdated), newValue),Toast.LENGTH_LONG).show();
return true;
}
});
findPreference("port").setOnPreferenceChangeListener(
new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Toast.makeText(context,toastMessage(context.getResources().getString(R.string.portUpdated), newValue),Toast.LENGTH_LONG).show();
return true;
}
});
}
}
public static String toastMessage(String updated, Object newValue){
return updated + " " + newValue.toString();
}
}
我有很多应用程序,其中首选项确实有键盘建议,所以我认为它可行的方式。