I would like to customize my EditTextPreference. My goal is formatting the title text. Here is a relevant part of my 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" />
Here is the code behind:
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 ) );
}
}
This code isn’t elegant enough but works.
Donot override setDialogTitle, call setDialogTitle(“”) in each of the constructor. It is used by apps but not by the Preference component.