Java 自定义EditTextPreference

Java 自定义EditTextPreference,java,android,sharedpreferences,Java,Android,Sharedpreferences,我想自定义我的EditTextPreference。我的目标是格式化标题文本。以下是我的prefs.xml的相关部分 这段代码不够优雅,但可以工作。不要重写setDialogTitle,在每个构造函数中调用setDialogTitle(“”)。它由应用程序使用,但不由首选项组件使用 我的目标是格式化或扩展来自静态xml的文本。你的解决方案应该是清楚的,而不是简单的。什么是“它被应用程序使用,但不被首选项组件使用”?在构造函数中,EditTextPreference直接访问android:dial

我想自定义我的EditTextPreference。我的目标是格式化标题文本。以下是我的prefs.xml的相关部分


这段代码不够优雅,但可以工作。

不要重写setDialogTitle,在每个构造函数中调用setDialogTitle(“”)。它由应用程序使用,但不由首选项组件使用

我的目标是格式化或扩展来自静态xml的文本。你的解决方案应该是清楚的,而不是简单的。什么是“它被应用程序使用,但不被首选项组件使用”?在构造函数中,EditTextPreference直接访问android:dialogTitle属性,并设置内部标题字符串,因此覆盖setDialogTitle将不会帮助Super(上下文,属性);setDialogTitle(context.getResources().getString(R.string.app_name)+attrs.getAttributeValue(0));在构造器中没有帮助在所有构造器中,不只是在一个构造器中没有帮助,因为中间的构造器(ctx,attrs)只被调用。
<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 ) );
}
}