android:singleLine of TextView is nolonger in the “Deprecated”?

拟墨画扇 提交于 2019-12-08 21:08:42

问题


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"
/>

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/7026121/androidsingleline-of-textview-is-nolonger-in-the-deprecated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!