0
我正在嘗試爲我的音樂應用實施通知。它包括播放/暫停和下一個按鈕,以及帶有選取框的TextView,以便歌曲標題滾動。當我嘗試更改播放/暫停按鈕圖標時,選取框文本將重置。Android:通知中更新文本而不重置動畫
這是我的通知佈局文件:
<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>
和通知類:
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()
工程完全按照預期,改變圖標,但我TextView的重置它的位置。有沒有辦法改變圖標而不重置整個佈局?
似乎並沒有改變任何東西:( –
你跟 –
一注4工作哪個版本的Android 5.0.1運行只是爲了澄清,按鈕正確更改,但調用'setPausePlayIcon()'也會重設我的TextView的'滾動',我希望滾動平滑而不間斷。 –