开发者

android:singleLine of TextView is nolonger in the "Deprecated"?

I am facing a problem of android:ellipsize that doesn't work in TextView. But to work well for android:singleLine.

I've heard that android:singleLine is "Deprecated", but it is not written in the reference in Android Developer.

https://developer.android.com/reference/android/widget/TextView.html#attr_android:singleLine

android:singleLine is no longer in 开发者_运维百科the "Deprecated"?

ADDED: I solved this problem myself.

As it turns out, android:scrollHorizontally="true" of TextView's attribute is not reflected in xml file.

So, I tried to use setHorizontallyScrolling method, it worked.

*xml:*
<TextView
  android:id="@+id/text"
  android:ellipsize="end"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
/>

*code:*
TextView textView = (TextView)findViewByID(R.id.text);
textView.setHorizontallyScrolling(true);

but, I add "android:inputType="text" in xml like following, it doesn't work. Please be careful.

*xml:*
<TextView
  android:id="@+id/text"
  **android:inputType="text"**
  android:ellipsize="end"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
/>


Try also setting the IME input to short text or something like that. it might work. there are a lot of issues with elipsize which i was also having at a point and didn't manage to solve. in my case it was connected to editTexts mostly and other components taking away the focus off the view. Focus is needed in order for Elipsize to work.


I am not sure if android:singleLine of TextView is nolonger in the “Deprecated”, because inside the deprecated constructor of TextView, there is a comment with regard to singleLine configuration..

// If set, the input type overrides what was set using the deprecated singleLine flag.

singleLine = !isMultilineInputType(inputType);

Source code: around 1156L of core/java/android/widget/TextView.java - platform/frameworks/base - Git at Google

Since Google leaves a comment saying that singleLine flag is deprecated, (although it is not written in the developer site) it may be so.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜