我想定制我的EditTextPreference。我的目标是格式化标题文本。以下是我的prefs.xml的相关部分
<com.widgets.FormattedEditTextPreference
android:dialogTitle="android password"
android:summary="password to this app"
android:inputType="textPassword"
android:key="sLoginPassw"
android:title="android password" />下面是代码:
public class FormattedEditTextPreference extends EditTextPreference {
public FormattedEditTextPreference( Context context, AttributeSet attrs, int defStyle ) {
super( context, attrs, defStyle );
setDialogTitle( context.getResources().getString( R.string.app_name )+attrs.getAttributeValue( 0 ) );
}
public FormattedEditTextPreference( Context context, AttributeSet attrs ) {
super( context, attrs );
setDialogTitle( context.getResources().getString( R.string.app_name )+attrs.getAttributeValue( 0 ) );
}
public FormattedEditTextPreference( Context context ) {
super( context );
setDialogTitle( context.getResources().getString( R.string.app_name ) );
}
}这段代码不够优雅,但能工作。
发布于 2012-09-12 18:36:32
不要覆盖setDialogTitle,在每个构造函数中调用setDialogTitle("")。它被应用程序使用,但不被首选项组件使用。
https://stackoverflow.com/questions/12394278
复制相似问题