应用EditTextPreference进行系统配置,感觉EditTextPreference只显示大小标题,点击修改才能看到值,不够简单明了。
想要实现小标题显示内容效果:
功能实现:
public class SysCfg extends PreferenceActivity { @SuppressWarnings("deprecation") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.addPreferencesFromResource(R.xml.syscfg); final EditTextPreference serverip = (EditTextPreference)findPreference("ServerIP"); SharedPreferences shp = PreferenceManager.getDefaultSharedPreferences(this); serverip.setSummary(shp.getString("ServerIP", "12.12.12.12")); serverip.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { // TODO Auto-generated method stub serverip.setSummary(newValue.toString()); serverip.setDefaultValue(newValue); return true; } }); } }
XML
<?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > <PreferenceCategory android:title="@string/IPaddress"> <EditTextPreference android:key="ServerIP" android:title="服务器IP地址设置" android:summary="点击输入" android:dialogTitle="输入IP地址" android:defaultValue="10.10.10.10"/> </PreferenceCategory> <PreferenceCategory android:title="@string/updateset"> <CheckBoxPreference android:title="@string/autoupdate"/> </PreferenceCategory> </PreferenceScreen>
标签:EditTextPreference,小标题,ServerIP,修改,serverip,Override,newValue From: https://www.cnblogs.com/xiaojian365/p/18294142