首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用椭圆大小结尾在单行中设置AutocompleteTextView提示

使用椭圆大小结尾在单行中设置AutocompleteTextView提示
EN

Stack Overflow用户
提问于 2016-08-29 17:24:38
回答 3查看 2.3K关注 0票数 1

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

我使用的是singleLine="true"maxLines="1"ellipsize="end"

但是,提示仍然显示在两行中。尽管文本设置为单行。但我需要的提示应该也需要在单行中显示。Android Studio中的预览在一行中显示了提示。但当我在设备上运行它时,它在2行代码中显示。(S5,Nexus-5,Nexus-6,J7)。

我还希望imeOption应该总是搜索。即imeOptions="actionSearch",因此我不能将其更改为actionNext。

下面是我的XML代码:

代码语言:javascript
复制
       <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>

有没有人能把我面临的问题说清楚?因为我想我已经使用了所有可能的解决方案,但提示仍然不在一行中。

EN

回答 3

Stack Overflow用户

发布于 2016-08-29 17:36:22

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

代码语言:javascript
复制
<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"

代码语言:javascript
复制
<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"/>
票数 2
EN

Stack Overflow用户

发布于 2018-02-02 02:51:53

AutoCompleteTextView上设置android:inputType="text"它对我有效,与android:ellipsize="end"不同的是,文本没有留在'...‘最终,但它确实达到了预期。

票数 0
EN

Stack Overflow用户

发布于 2021-08-19 07:22:42

代码语言:javascript
复制
android:completionThreshold="1"
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39202709

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档