2017-02-19 25 views
4

如何使用MaxLines而不是SingleLine选取框?使用maxLines的选框

这是我的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后,我setSelectedTextView

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

问题是android:singleLine已被弃用,所以我不得不使用android:maxLines代替,但字幕不要使用它。

回答

1

您可以尝试使用此:

android:maxLength = "10" 

OR

设置android:maxLines="1"后,你必须设置你的inputType了。所以,请设置你的android:inputType="text",那应该可以做到。

+0

我们不能对一个TextView –

+0

设置的inputType为什么不呢?看到这个链接https://developer.android.com/reference/android/widget/TextView.html –

2

在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);