2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

android PreferenceFragmentCompatのEditTextPreferenceを改行させないようにする方法

2
Posted at

なかなか調べても出てこなかったので、
EditTextPreferenceで改行ができてしまい、すこし操作性が悪かったので
改行をできなくするようにする方法です。

というよりはDialogで呼ばれるEditTextのレイアウトを指定する方法です。

preferences.xml

<EditTextPreference
      android:dialogLayout="@xml/prefernce_custom_edittext"
      android:key="userName"
      android:title="ユーザー名" />

android:dialogLayoutを設定します。

prefernce_custom_edittext.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <EditText
        android:id="@android:id/edit"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="18dp"
        android:paddingRight="18dp"
        android:inputType="text|textNoSuggestions" />

</LinearLayout>

これで普段扱っているように自由にカスタマイズできます。

スクリーンショット 2019-04-11 14.24.58.png

改行できない!よかったよかった!

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?