Custom notification marquee text doesnt work android

泪湿孤枕 提交于 2019-12-10 15:48:39

问题


Hi im trying to make part of my text in the notification manager marquee but doesnt work i tried this:

  <TextView
    android:id="@+id/title_text"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:fadingEdge="horizontal"
    android:gravity="bottom"
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true"                                     
    android:focusable="true"
    android:focusableInTouchMode="true"              
    android:singleLine="true"
    android:textSize="15sp"
    android:textStyle="bold" >
  </TextView>

and in my .java i use remoteview:

Notification notification = new Notification(icon, tickerText, when);
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification);

contentView.setTextViewText(R.id.title_text, "This is a very long text which is not fitting in the screen so it needs to be marqueed");

i would like to have marquee for that title_text This is a very long text which is not fitting in the screen so it needs to be marqueed

but the marquee doesnt work just stays static what i can do?

thank you.


回答1:


i changed my xml:

  <TextView
    android:id="@+id/title_text"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:fadingEdge="horizontal"
    android:gravity="bottom"
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="false"                                     
    android:focusable="true"
    android:focusableInTouchMode="true"              
    android:singleLine="true"
    android:textSize="15sp"
    android:textStyle="bold" 
    android:textColor="#fff">
    <requestFocus/> 
  </TextView>

i added <requestFocus/> and now my marquee works perfect.




回答2:


According to the docs, setting the scrollHorizontally attribute to true will NOT wrap the text at the edge. Try setting it to false so the ellipsize attribute is used.




回答3:


I lost a day to realize thats the marquee effect is done by this method from NotificationCompat.Builder: setTicker which support RemoteView

I really hope that answer save many lives :) (almost lost my hair)



来源:https://stackoverflow.com/questions/12990405/custom-notification-marquee-text-doesnt-work-android

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