使用 maxLines 选取框

Marquee using maxLines

如何使用 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">

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

TextView txtView=(TextView) findViewById(R.id.MarqueeText);
txtView.setSelected(true);

问题是 android:singleLine 已被弃用,所以我必须改用 android:maxLines,但选取框无法使用它。

你可以试试这个:

android:maxLength = "10"

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

在XML

<TextView
    android:text="11111111111111111111111111111111111111111111111111111111111111"
    android:id="@+id/text_marquee"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:maxLines="1"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    />

在Java

((TextView)findViewById(R.id.text_marquee)).setHorizontallyScrolling(true);
((TextView)findViewById(R.id.text_marquee)).setSelected(true);