6

I've just tried to implement the fade effect for TextView in Android 4.0.3; however, it doesn't work.

fadingEdge="horizontal"
singleLine="true"
ellipsize="marquee"

This code works perfectly for 2.3.7 and below, but not working for 4.0.3. I'm wondering why is that so? and how to make fade effect for TextView?

My question is the same as this one: http://groups.google.com/group/android-developers/browse_thread/thread/97131b20de8b2ebd , but no answer yet.

Pete Houston
  • 14,931
  • 6
  • 47
  • 60

2 Answers2

4

It is a bit late, but that may help people who have the same question.

I have had this problem on different phones, and it could come from that :

  • on Android 4.0.x, it seems that the TextView have to be focusable, otherwise fade effect won't work. So try adding this :

    android:focusable="true" android:focusableInTouchMode="true"

  • if that does not work, you could try android:lines="1", but i think that android:singleLine="true", which is deprecated, works better

  • sometimes, you need to programmatically call setSelected(true) on the textView to get the fade effect. Please check this link : Is there a way to make ellipsize="marquee" always scroll?

Community
  • 1
  • 1
Yves Delerm
  • 785
  • 4
  • 10
  • if you set `android:focusableInTouchMode` then users must touch to receive the focus and the fading effect happens. however, I want it to display with fading effect normally as in GB 2.3.x – Pete Houston Jun 07 '12 at 02:32
  • did you try the different combinations of android:focusable and android:focusableInTouchMode ? If it still does not work, I'm afraid the only solution is to programmatically call setSelected() on your textView – Yves Delerm Jun 07 '12 at 09:43
  • i know that if set `android:focusableInTouchMode`, it will work as long as user touch the `TextView` in order to receive focus and it will transform into fading effect. what I mean is the natural state of `TextView` should be like that, no touch required. – Pete Houston Jun 07 '12 at 11:08
  • As I tested this on a Galaxy Nexus, I have had no problem with android:focusableInTouchMode="true". With touch mode activated, well, I guess you will need to try some programmatic solution from the link above. – Yves Delerm Jun 07 '12 at 13:56
  • 2
    To get it to work on a Nexus running Android 4.4 I needed to set ellipsize="marquee", marqueeRepeatLimit="0" and fadingEdge="horizontal" in the xml and use setSelected(true) programmatically. Without setting marqueeRepeatLimit="0" I was getting automatically scrolling text which is not what I wanted. – Abid H. Mujtaba Mar 14 '14 at 14:55
  • @ShobhitPuri I looked and I looked (through several git repos) but I can't for the life of me find this chunk of code. Sorry. – Abid H. Mujtaba Nov 19 '15 at 07:18
1

As of API level 14 fadingEdge is deprecated and ignored so in order to make fading edge work on Android 4.0.3 you must use requiresFadingEdge instead.

Wayne
  • 6,361
  • 10
  • 46
  • 69