使用 maxLines 选取框

Jéw*_*ôm' 5 android ellipsis textview

如何使用 MaxLines 而不是 SingleLine 来制作选取框?

这是我的 TextView :

<TextView
    android:text="bla bla bla bla bla bla"
    android:id="@+id/MarqueeText" 
    android:layout_width="30dp"
    android:layout_height="wrap_content" 
    android:singleLine="true"
    android:ellipsize="marquee" 
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:freezesText="true">
Run Code Online (Sandbox Code Playgroud)

在我的 code.java 之后setSelected我TextView:

TextView txtView=(TextView) findViewById(R.id.MarqueeText);
txtView.setSelected(true);
Run Code Online (Sandbox Code Playgroud)

问题是android:singleLine已被弃用,所以我必须使用android:maxLines它,但选框不适用于它。

Har*_*wal 1

你可以尝试使用这个:

android:maxLength = "10"
Run Code Online (Sandbox Code Playgroud)

或者

设置后android:maxLines="1",您也必须设置您的inputType。所以,设置你的android:inputType="text"就可以了。