java自定义EditTextPreference
我想自定义我的编辑文本首选项。我的目标是格式化标题文本。以下是我的序言的相关部分。eem
<com.widgets.FormattedEditTextPreference
安卓:dialogTitle="安卓 password"
安卓:summary="password to this app"
安卓:inputType="textPassword"
安卓:key="sLoginPassw"
安卓:title="安卓 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 ) );
}
}
这段代码不够优雅,但很有效
# 1 楼答案
不要重写setDialogTitle,在每个构造函数中调用setDialogTitle(“”)。它由应用程序使用,但不由首选项组件使用