inote记事工具-PreferenceScreen及PreferenceActivity使用

源码及APK下载: http://files.note.sdo.com/7pq1Y~jGuguFnM0b0006dI

Android提供了如下的设置页面,通过PreferenceScreen及PreferenceActivity的组合就可以实现。

1. 创建一个Settings类继承于PreferenceActivity,在onCreate中加载创建好的设置界面即可。

public class Settings extends PreferenceActivity {
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		addPreferencesFromResource(R.xml.settings);
	}
}
2. 设置界面显示 (有自定义DialogPreference)

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    android:title="@string/app_name">

<PreferenceCategory android:title="@string/settings_lock" 
    xmlns:android="http://schemas.android.com/apk/res/android">
   
<cn.sh.zyh.inote.pref.LockPreference
    android:summary="@string/lock_summary" 
    android:key="@string/lock_key"
    android:title="@string/lock_title"
    />

</PreferenceCategory>

<PreferenceCategory android:title="@string/settings_backup" 
    xmlns:android="http://schemas.android.com/apk/res/android">
   
<cn.sh.zyh.inote.pref.ExportPreference
    android:summary="@string/export_summary" 
    android:title="@string/export_title" 
    android:key="@string/export_key"/>
    
<cn.sh.zyh.inote.pref.RestorePreference
    android:summary="@string/restore_summary" 
    android:title="@string/restore_title" 
    android:key="@string/restore_key"/>

</PreferenceCategory>
</PreferenceScreen>


3. 由于Android只提供了有限的几个DialogPreference,如果需要复杂的Dialog显示,可以继承DialogPreference实现自定义界面
public class LockPreference extends DialogPreference {
	public LockPreference(Context context, AttributeSet attrs) {
		super(context, attrs);

		setDialogLayoutResource(R.layout.lock_pop); //设置弹出窗口的layout
	}

	@Override
	protected void onBindDialogView(View view) {
		super.onBindDialogView(view);

		updateUI(view); //更新界面
	}

	private void updateUI(View view) {

	}

	@Override
	protected void onDialogClosed(boolean positiveResult) {
		super.onDialogClosed(positiveResult);

		if (positiveResult) {
			//点击确定按钮后,可执行的处理
		}
	}
}

下图密码窗口的layout文件(lock_pop)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical"
	android:layout_width="fill_parent" 
	android:layout_height="wrap_content"
    android:paddingLeft="5px"
    android:paddingRight="5px">
	
<TextView android:text="@string/curpwd" 
	android:layout_width="wrap_content" 
	android:layout_height="wrap_content"/>
<EditText 
    android:layout_height="wrap_content"
	android:id="@+id/curpwd" 
	android:layout_width="fill_parent"
	android:enabled="false"
	android:password="true"
	android:inputType="number"
	/>
<TextView android:text="@string/newpwd" 
	android:layout_width="wrap_content" 
	android:layout_height="wrap_content"/>
<EditText
    android:layout_height="wrap_content"
	android:id="@+id/newpwd" 
	android:layout_width="fill_parent"
	android:password="true"
	android:inputType="number"/>
<TextView android:text="@string/repeatpwd" 
	android:layout_width="wrap_content" 
	android:layout_height="wrap_content"/>
<EditText
    android:layout_height="wrap_content"
	android:id="@+id/repeatpwd" 
	android:layout_width="fill_parent"
	android:password="true"
	android:inputType="number"/>
<CheckBox android:id="@+id/cancelpwd" 
    android:layout_height="wrap_content"
	android:text="@string/cancelpwd" 
	android:layout_width="wrap_content"
	android:checked="false"/>
</LinearLayout>


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值