How to wrap preference title?

2019-03-26 21:26发布

In this picture, the title of my Preference does not wrap around its parent.

How can I make the title wrap to a new line?

Thanks.

enter image description here

xml:

<CheckBoxPreference
        android:key="keypref"
        android:summary="Summary text does wrap around the borders"
        android:title="The title of this preference is" >
</CheckBoxPreference>

2条回答
淡お忘
2楼-- · 2019-03-26 21:38

You would need to make custom layout which resembles default (android internal) CheckBoxPreference. In that xml text view of title should be with ellipsize set to Marque, repeat limit indefinite and scrollable set to horizontal. Than you can set layout of CheckBoxPreference with:

<CheckBoxPreference
    android:key="key_checkbox_pref"
    android:summary="Summary text does wrap around the borders"
    android:title="The title of this preference."
    android:layout="@layout/custom_checkbox_preferences_layout">

Hope that would work ;)

查看更多
SAY GOODBYE
3楼-- · 2019-03-26 21:39

Just an update to this. It's a String so you can use \n to create a newline.

<CheckBoxPreference
        android:key="keypref"
        android:summary="Summary text does wrap around the borders"
        android:title="The title of this preference\nis this." >
</CheckBoxPreference>
查看更多
登录 后发表回答