首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >定制EditTextPreference

定制EditTextPreference
EN

Stack Overflow用户
提问于 2012-09-12 18:31:12
回答 1查看 358关注 0票数 1

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

代码语言:javascript
复制
<com.widgets.FormattedEditTextPreference
    android:dialogTitle="android password"
    android:summary="password to this app"
    android:inputType="textPassword"
    android:key="sLoginPassw"
    android:title="android password" />

下面是代码:

代码语言:javascript
复制
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 ) );
}
}

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-12 18:36:32

不要覆盖setDialogTitle,在每个构造函数中调用setDialogTitle("")。它被应用程序使用,但不被首选项组件使用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12394278

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档