Уведомление Android TextView Marquee не работает?

Я пытаюсь создать настраиваемую строку состояния уведомлений, например Samsung Galaxy S3 stock Music Player. Я использую RemoteViews для пользовательского макета. Но мои компоненты textview не работают в режиме выделения.

Мои коды ниже. И где я ошибаюсь? Я потратил много времени на решение этой проблемы, но мне не повезло.

Панель уведомлений музыкального проигрывателя Samsung Galaxy S3:

введите здесь описание изображения

Это мой код макета xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="64dip"
        android:layout_height="64dip"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/imgViewIcon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/app_name"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/textViewNotifPlaylist"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:ellipsize="marquee"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:marqueeRepeatLimit="marquee_forever"
            android:singleLine="true"
            android:text="@string/app_name"
            android:textColor="#0094FF" >

            <requestFocus />
        </TextView>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="64dip"
        android:layout_marginLeft="3dip"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="horizontal" >

            <ImageButton
                android:id="@+id/imgBtnNotifPrevious"
                android:layout_width="40dip"
                android:layout_height="40dip"
                android:layout_marginRight="20dp"
                android:background="@drawable/button_circle"
                android:contentDescription="@string/media_previous"
                android:src="@drawable/media_btn_previous" />

            <ImageButton
                android:id="@+id/imgBtnNotifPlayPause"
                android:layout_width="40dip"
                android:layout_height="40dip"
                android:background="@drawable/button_circle"
                android:contentDescription="@string/media_play"
                android:src="@drawable/media_btn_play" />

            <ImageButton
                android:id="@+id/imgBtnNotifNext"
                android:layout_width="40dip"
                android:layout_height="40dip"
                android:layout_marginLeft="20dp"
                android:background="@drawable/button_circle"
                android:contentDescription="@string/media_next"
                android:src="@drawable/media_btn_next" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <TextView
                android:id="@+id/textViewNotifItem"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true" 
                android:ellipsize="marquee"
                android:marqueeRepeatLimit ="marquee_forever"
                android:scrollHorizontally="false"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:duplicateParentState="true"
                android:text="This is the long text and I want to this marquee mode." >

                <requestFocus 
                  android:focusable="true" 
                  android:focusableInTouchMode="true"
                  android:duplicateParentState="true" />
            </TextView>
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

И это мой код Java:

private void showNotification()
{
    final NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent piContent = ...;
    PendingIntent piPrevious = ...;
    PendingIntent piPausePlay = ...;
    PendingIntent piNext = ...;

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher)
            .setAutoCancel(false)
            .setTicker("This is ticker text")
            .setContentTitle(getString(R.string.app_name))
            .setContentText("This is content text")
            .setContentIntent(piContent);

    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_bar);
    remoteViews.setTextViewText(R.id.textViewNotifPlaylist, "Sample Playlist");
    remoteViews.setTextViewText(R.id.textViewNotifItem, "This is long text and I want to this at marquee mode");
    remoteViews.setOnClickPendingIntent(R.id.imgBtnNotifPrevious, piPrevious);
    remoteViews.setOnClickPendingIntent(R.id.imgBtnNotifPlayPause, piPausePlay);
    remoteViews.setOnClickPendingIntent(R.id.imgBtnNotifNext, piNext);

    builder.setContent(remoteViews);

    notificationManager.notify(R.string.app_name, builder.build());
}

person N3CAT1    schedule 09.09.2013    source источник
comment
Вы решили вышеуказанную проблему?   -  person nisha.113a5    schedule 31.12.2014


Ответы (1)


Marquee нуждается в том, чтобы текстовое представление получило фокус, поэтому вы можете перегрузить текстовое представление следующим образом:

public class MarqueeTextView extends TextView {  

public MarqueeTextView(Context appCon) {  
    super(appCon);  
}  

public MarqueeTextView(Context context, AttributeSet attrs) {  
    super(context, attrs);  
}  

public MarqueeTextView(Context context, AttributeSet attrs, int defStyle) {  
    super(context, attrs, defStyle);  
}  

@Override  
public boolean isFocused() {  
    return true;  
}  

@Override  
protected void onFocusChanged(boolean focused, int direction,  
        Rect previouslyFocusedRect) {  
}  

}

person alexcai    schedule 14.10.2013
comment
Но RemoteViews не позволяет использовать пользовательский TextView. Выдает ошибку RemoteViewsException. - person N3CAT1; 13.11.2013