【问题标题】:AutoCompleteTextview multi line (not dropdown but textbox)AutoCompleteTextview 多行(不是下拉列表,而是文本框)
【发布时间】:2013-12-26 09:01:47
【问题描述】:

我正在使用一个自动完成功能。我想将此自动完成显示为多行。我不想将下拉菜单显示为多行,但我想将文本框显示为多行。

我还在 .xml 文件中使用多行属性,但它在键盘上显示下一行键,我不想使用用户按此键并继续下一行。

现在发生了什么

完成空间后,我在文本框中输入了一些内容,它正在水平滚动。并在一行中显示所有文本。

我想要什么

假设用户键入并在完成文本框的空间后,然后自动光标将转到下一行,因此用户可以一次看到所有文本而无需水平滚动。

这是我的代码。

<AutoCompleteTextView
                android:id="@+id/txtTags"
                android:layout_width="fill_parent"
                android:layout_height="44dip"
                android:layout_marginLeft="12dip"
                android:layout_marginRight="12dip"
                android:background="@drawable/borderforloginedittext"
                android:gravity="center_vertical"
                android:hint="eg: Breakfast, spicy, italian "
                android:inputType="textPersonName|textImeMultiLine"
                android:imeOptions="actionSearch"
                android:paddingLeft="70dp"
                android:scrollHorizontally="false"
                android:verticalScrollbarPosition="right"
                 android:dropDownHeight="fill_parent"
                android:dropDownWidth="match_parent"
                android:textColor="#333333"
                android:textColorHint="#999999"
                android:textSize="16sp" >
            </AutoCompleteTextView>    

我需要 impeoption 作为 actionsearch,以便用户可以按键盘的搜索键。这就是我不能使用 textmultiline 的原因,因为它将搜索键替换为下一行键。

请提供一些参考或提示。

【问题讨论】:

  • 我已经为你提供了工作示例答案,请接受并投票。

标签: android multiline autocompletetextview


【解决方案1】:

我没有找到任何答案。因为我想使用 imeoption 作为 actionSearch,然后我希望我的自动完成功能像多行 EditText

因此,我将 actionsearch 作为一个 ime 选项删除并放置多行。这不是我想要的,但仍然满足至少达到 50%。

<AutoCompleteTextView
    android:id="@+id/txtTags"
    android:layout_width="fill_parent"
    android:layout_height="44dip"
    android:layout_marginLeft="12dip"
    android:layout_marginRight="12dip"
    android:background="@drawable/borderforloginedittext"
    android:hint="eg: Breakfast, spicy, italian "
    android:inputType="textPersonName|textMultiLine"
    android:paddingLeft="70dp"                
    android:dropDownHeight="fill_parent"
    android:dropDownWidth="match_parent"
    android:textColor="#333333"
    android:textColorHint="#999999"
    android:textSize="16sp" >
</AutoCompleteTextView>    

这段代码为我提供了一个使用多行的选项。

【讨论】:

    【解决方案2】:

    在您的 xml 中进行以下更改。

    <AutoCompleteTextView
                android:id="@+id/txtTags"
        <!--remove below width as fill_parent and set fixed width as per your need-->
                android:layout_width="fill_parent"
                android:layout_height="44dip"
                android:layout_marginLeft="12dip"
                android:layout_marginRight="12dip"
                android:background="@drawable/borderforloginedittext"
                android:gravity="center_vertical"
                android:hint="eg: Breakfast, spicy, italian "
      <!-- please replace textImeMultiLine with textMultiLine.--> 
                android:inputType="textPersonName|textImeMultiLine"
                android:imeOptions="actionSearch"
                android:paddingLeft="70dp"
                android:scrollHorizontally="false"
                android:verticalScrollbarPosition="right"
                 android:dropDownHeight="fill_parent"
                android:dropDownWidth="match_parent"
                android:textColor="#333333"
                android:textColorHint="#999999"
                android:textSize="16sp" >
              </AutoCompleteTextView>
    

    【讨论】:

    • 如果我为这个自动完成设置硬编码宽度,比如 width=300,对兼容性有好处吗?我不这么认为。
    • 那么在这种情况下使用android:maxLength=""android:Width="" 但我认为更好的选择是使用为设备密度生成该xml 视图。我的意思是根据屏幕宽度创建不同的 xml 文件。
    • 如果我使用 textmultiline 然后键盘图标从搜索替换到下一个我不想看到我的问题的最后一行。
    【解决方案3】:

    很简单,你只需要设置

    android:singleLine="false"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-12
      • 2015-08-14
      • 1970-01-01
      • 2015-02-14
      • 1970-01-01
      • 2020-03-05
      相关资源
      最近更新 更多