Android: Update text in notification without resetting animation -
i'm trying implement notification music app. it's comprised of play/pause , next buttons, , textview marquee enabled song title scrolls. when try change play/pause buttons icon, marquee text resets.
here's notification layout file:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> <imagebutton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:src="@drawable/perm_group_audio_settings" android:id="@+id/album_art" android:background="#00000000" /> <textview android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_torightof="@+id/album_art" android:ellipsize="marquee" android:singleline="true" android:marqueerepeatlimit="marquee_forever" android:fadingedge="horizontal" android:focusable="true" android:focusableintouchmode="true" android:id="@+id/song_name"> <requestfocus/> </textview> <linearlayout android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_torightof="@+id/album_art" android:layout_below="@+id/song_name" android:orientation="horizontal" android:gravity="right"> <imagebutton android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="right" android:id="@+id/player_stop" android:background="#00000000" android:src="@drawable/ic_media_stop"/> <imagebutton android:layout_width="wrap_content" android:layout_height="match_parent" android:id="@+id/player_pause" android:background="#00000000" android:src="@drawable/ic_media_pause"/> <imagebutton android:layout_width="wrap_content" android:layout_height="match_parent" android:id="@+id/player_next" android:background="#00000000" android:src="@drawable/ic_media_next"/> </linearlayout> </relativelayout>
and notification class:
public class mediaplayernotification extends notification { private context context; private notificationmanager m_manager; private notificationcompat.builder m_builder; private remoteviews m_view; private notification m_notification; public mediaplayernotification(context context) { this.context = context; m_builder = new notificationcompat.builder(context) .setcontenttitle(notification_title) .setsmallicon(notification_icon) .setongoing(true) .setpriority(notification.priority_max); m_view = new remoteviews(context.getpackagename(), r.layout.notification_player); m_view.setimageviewresource(r.id.player_stop, icon_stop); m_view.setimageviewresource(r.id.player_pause, icon_pause); m_view.setimageviewresource(r.id.player_next, icon_next); m_builder.setcontent(m_view); m_notification = m_builder.build(); m_manager = (notificationmanager)context.getsystemservice(context.notification_service); m_manager.notify(2, m_notification); } public void setpauseplayicon(int iconid) { m_view.setimageviewresource(r.id.player_pause, iconid); m_manager.notify(2, m_notification); } public void setnowplaying(string name) { m_view.settextviewtext(r.id.song_name, name); m_manager.notify(2, m_notification); } }
setpauseplayicon()
works expected , changes icon, textview resets it's position. there way change icon without resetting entire layout?
try this:
public void setpauseplayicon(int iconid) { m_view.setimageviewresource(r.id.player_pause, iconid); m_builder.setcontent(m_view); m_manager.notify(2, m_builder.build()); }
Comments
Post a Comment