“In-place” EditTextPreference

非 Y 不嫁゛ 提交于 2019-12-10 12:01:44

问题


I used the XML syntax to create a PreferenceActivity with a PreferenceScreen. I added an EditTextPreference and noticed that this renders as a dialog. Is there a way to make the EditText in-place i.e., the text field is displayed right in the PreferenceScreen instead of popping up as a dialog?


回答1:


In case anyone comes across the same problem, this cannot be accomplished with the built-in Preference classes, but you can subclass Preference, and override getView() to return a ViewGroup containing an in-line EditText (or simply the EditText itself).

You could probably achieve this by providing the android:layout attribute in the XML too (although I haven't tried this).

EDIT:
I tried the android:layout approach above, and it works pretty well.




回答2:


add android:layout="@layout/your_loyout".

where your_layout.xml is like

<EditText android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" />



来源:https://stackoverflow.com/questions/10651523/in-place-edittextpreference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!