问题
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