Android的全息主题不换行多行微调下拉项[复制](Android Holo theme does

2019-08-01 22:30发布

This question already has an answer here:

  • Spinner does not wrap text — is this an Android bug? 14 answers

I recently just implemented the holo theme into my android app. After doing this, any spinner that I have, where the drop down item is multiple lines long, will not wrap the text to multiple lines. Each drop down item is kept all on one line and truncated to a certain length.

Here is my xml for the drop down resource for the spinner

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@android:id/text1"
style="?android:attr/spinnerDropDownItemStyle"
android:singleLine="false"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="none" />

This works on older versions of android before ICS and the holo theme.

Has anyone else encountered this issue?

Answer 1:

正如我在曾经提到: 微调不换行文字-这是一个Android的bug?

我认为这是一个错误在Android上。 你可以试试这个。 删除从文本的空间,然后显示它会正常工作。 如果的TextView的长度为<该字符串的,它忽略了空间之后的所有字符。 对于一个变通办法,你可以试试这个:

将文件添加到与样品代码multiline_spinner_dropdown_item.xml名为RES /布局文件夹:

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/sample_text"
style="?android:attr/spinnerDropDownItemStyle"
android:singleLine="false"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:ellipsize="marquee" />

当你正在创建的微调从这个布局创建它。

就像是 :

ArrayAdapter.createFromResource(this, items, R.layout.multiline_spinner_dropdown_item);

基本上,复制android.R.layout.simple_spinner_dropdown_item布局到项目,并通过在CheckedTextView设置单行属性设置为false修改布局。



文章来源: Android Holo theme does not wrap multiple line spinner dropdown items [duplicate]