Binoy Babu
Binoy Babu

Reputation: 17119

Ticker TextView in Notification Layout

Is there a way to make a TextView in a custom Notification layout look like a ticker? I'm using the following code to set Notification layout.

mNotificaionView = new RemoteViews(getPackageName(), R.layout.status_bar);
mNotificaionView.setTextViewText(R.id.ticker, getLongText());
mNotification.contentView = mNotificaionView;

And the following attrs for TextView in status_bar.xml

android:singleLine="true" 
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true" 

In fewer words, how do I create a ticker like TextView in a RemoteViews object?

Upvotes: 0

Views: 2051

Answers (2)

Udinic
Udinic

Reputation: 3064

Look at Any.DO SmallWidget(4x1).

It's a ticker that fades text in and out. And it's an AppWidget. How does it work?

  • Create an array of colors for the text, from the opaque, to the transparent and then to the opaque again.
  • Create an alarm that when triggered it changes the text's color to the current color in the above array (the current index in the array will be saved).
  • Make the alarm create a another one, to do the same for the next index in the array
  • When the index is in the transparent part of the array - change the text to the next line we want to present
  • When reaching the last index, we'll reset the array's index, and set an alarm to start the whole thing again. That alarm will be set to about 5 seconds from that moment (to give the user enough time to read the text)

The problem - battery consumption. All those alarms don't do well with the battery, but test it to see how bad is it first.

I never tried this on a notification bar widget, but since they are built with the same technique, this might work.

Good luck!

Upvotes: 1

Leaudro
Leaudro

Reputation: 1021

This should work, but only while your View has focus. See this answer, it may help you. Android notification Marquee not working

Upvotes: 1

Related Questions