【问题标题】:Set AutocompleteTextView hint in a single line with Ellipsize end在 Ellipsize 结束的单行中设置 AutocompleteTextView 提示
【发布时间】:2016-08-29 09:24:38
【问题描述】:

我想在一行中设置我的 AutocompleteTextView 的提示,并在最后用点(...)截断额外的字符串。

我正在使用singleLine="true"maxLines="1"ellipsize="end"

但提示仍然显示为两行。虽然文本设置为单行。但我需要的提示也需要单行显示。 Android Studio 中的预览以单行显示提示。但是当我在设备上运行它时,它会显示为 2 行。(S5、Nexus-5、Nexus-6、J7)。

我还希望 imeOption 应该始终是搜索。即imeOptions="actionSearch" 因此我无法将其更改为 actionNext。

下面是我的 XML 代码:

       <RelativeLayout
            android:id="@+id/liLaySearchMap"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:visibility="gone"
            android:paddingLeft="10dp"
            android:background="@color/cococo"
            android:paddingRight="10dp">

            <AutoCompleteTextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="@dimen/five_dp"
                android:background="@color/white"
                android:padding="@dimen/two_dp"
                android:scrollHorizontally="true"
                android:drawablePadding="@dimen/two_dp"
                android:singleLine="true"
                android:lines="1"
                android:maxLines="1"
                android:ellipsize="end"
                android:textSize="@dimen/twelve_sp"
                android:drawableLeft="@drawable/ic_action_search"
                android:inputType="text"
                android:hint="A Very Long Hint Text Which Need To Be Tuncated At the End In Single Line"
                android:id="@+id/edSearch"
                android:imeOptions="actionSearch"
                android:layout_alignParentLeft="true"
                android:layout_toLeftOf="@+id/tvCancel"
                />

            <TextView
                android:id="@+id/tvCancel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:layout_gravity="center"
                android:layout_margin="@dimen/five_dp"
                android:text="@string/cancel"
                android:textSize="@dimen/twelve_sp"
                android:textColor="@color/tw__composer_red"
                android:padding="@dimen/five_dp"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"/>

            </RelativeLayout>

任何人都可以解决我面临的问题。我认为我已经使用了所有可能的解决方案,但提示仍然不是单行。

【问题讨论】:

    标签: android android-layout android-edittext autocompletetextview


    【解决方案1】:

    这些是我设备上的屏幕截图,我尝试的 xml 如下

    <AutoCompleteTextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:background="@color/white"
            android:padding="2dp"
            android:scrollHorizontally="true"
            android:drawablePadding="2dp"
            android:singleLine="true"
            android:lines="1"
            android:maxLines="1"
            android:ellipsize="end"
            android:textSize="16sp"
            android:inputType="text"
            android:drawableLeft="@mipmap/ic_launcher"
            android:hint="A Very Long Hint Text Which Need To Be Tuncated At the End In Single Line"
            android:id="@+id/edSearch"
            android:imeOptions="actionSearch"/>
    

    尝试在AutoCompleteTextView 上设置android:inputType="text" 它对我有用

    <AutoCompleteTextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:maxLines="1"
            android:inputType="text"
            android:ellipsize="end"
            android:imeOptions="actionNext"
            android:hint="this is to check if it's getting truncated and in single line or not"/>
    

    【讨论】:

    • @PravinsinghWaghela 我在我的系统上尝试过它完美地工作我真的想知道为什么它在你的情况下不起作用。尝试清理并构建或卸载应用并在您的设备中重新安装
    • 在设备上而不是在 android studio 的预览屏幕上?
    • 嗯,我看到的是你拥有我拥有的所有参数。只是你增加了字体大小。其余的都是一样的。它不适用于三星 S5、三星 J7。 Nexus 5,Nexus 6。在模拟器和预览屏幕上它可以工作。请再看一遍问题。
    【解决方案2】:

    AutoCompleteTextView 上设置android:inputType="text" 对我有用,与android:ellipsize="end" 不同,文本最后没有保留“...”,但确实符合预期。

    【讨论】:

      【解决方案3】:
      android:completionThreshold="1"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-12-20
        • 2013-09-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-09-09
        • 1970-01-01
        相关资源
        最近更新 更多