更改首选项上的Edittext方面

时间:2014-09-09 08:26:43

标签: java android preferences

我创建了一个自定义EditTextPreference,用于在首选项中显示和内联Edittext。 当我在xml ressources文件中添加它时,如下所示:

        <app.FormEntryPreference
            android:key="pref_key"
            android:title="@string/pref_string"/>

我得到了这个结果:

image 1

具有我想要的风格(android:Theme.Holo)。

当我以编程方式添加我的偏好时:

FormEntryPreference form0 = new FormEntryPreference(getActivity().getApplicationContext(), null);   

我得到了不同的结果:

image2

该样式应用于用于EditText的布局资源:

 <EditText        
    style="@style/Style.that.inherits.from.holo"
    android:inputType="text"
    android:id="@+id/form_id"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</EditText>

我希望在这两种情况下都能获得同样的形状。

1 个答案:

答案 0 :(得分:0)

好的,所以同事解决了这个问题,而不是

FormEntryPreference form0 = new FormEntryPreference(getActivity().getApplicationContext(), null);

我只需删除“getApplicationContext()”,它就像这样的魅力:

FormEntryPreference form0 = new FormEntryPreference(getActivity(), null);   
相关问题