Исправление большого макета уведомлений Android

Я пытаюсь создать собственное уведомление для своего музыкального плеера. Я создал h пользовательский макет, такой как Google Play Music, и использовал его в коде уведомления, но я не получаю расширенный вид уведомления. Ниже приведены мои коды:--tification_custom_expanded_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="128.0dip"
tools:ignore="ContentDescription" >

<ImageView
    android:id="@+id/notification_expanded_base_image"
    android:layout_width="128.0dip"
    android:layout_height="128.0dip"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:scaleType="fitXY" />

<LinearLayout
    android:id="@+id/notification_expanded_buttons"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_toRightOf="@+id/notification_expanded_base_image"
    android:divider="?android:listDivider"
    android:dividerPadding="12.0dip"
    android:gravity="center_vertical"
    android:orientation="horizontal"
    android:showDividers="middle" >

    <ImageButton
        android:id="@+id/notification_expanded_base_previous"
        android:layout_width="0dp"
        android:layout_height="48.0dip"
        android:layout_weight="1"
        android:background="?android:selectableItemBackground"
        android:padding="10.0dip"
        android:scaleType="fitCenter"
        android:src="@drawable/btn_playback_previous_light" />

    <ImageButton
        android:id="@+id/notification_expanded_base_play"
        android:layout_width="0dp"
        android:layout_height="48.0dip"
        android:layout_weight="1"
        android:background="?android:selectableItemBackground"
        android:padding="10.0dip"
        android:scaleType="fitCenter"
        android:src="@drawable/btn_playback_pause_light" />

    <ImageButton
        android:id="@+id/notification_expanded_base_next"
        android:layout_width="0dp"
        android:layout_height="48.0dip"
        android:layout_weight="1"
        android:background="?android:selectableItemBackground"
        android:padding="10.0dip"
        android:scaleType="fitCenter"
        android:src="@drawable/btn_playback_next_light" />
</LinearLayout>

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="1dp"
    android:layout_above="@+id/notification_expanded_buttons"
    android:layout_alignParentRight="true"
    android:layout_toRightOf="@+id/notification_expanded_base_image"
    android:background="?android:dividerHorizontal" />

<ImageButton
    android:id="@+id/notification_expanded_base_collapse"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:background="?android:selectableItemBackground"
    android:padding="8.0dip"
    android:src="@drawable/btn_notification_collapse" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_gravity="center_vertical"
    android:layout_toLeftOf="@+id/notification_expanded_base_collapse"
    android:layout_toRightOf="@+id/notification_expanded_base_image"
    android:orientation="vertical"
    android:paddingLeft="8.0dip"
    android:paddingTop="8.0dip" >

    <TextView
        android:id="@+id/notification_expanded_base_line_one"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:fadingEdge="horizontal"
        android:singleLine="true"/>

    <TextView
        android:id="@+id/notification_expanded_base_line_two"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:fadingEdge="horizontal"
        android:singleLine="true"/>

    <TextView
        android:id="@+id/notification_expanded_base_line_three"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:fadingEdge="horizontal"
        android:singleLine="true"/>
</LinearLayout>

Java-код

    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    Notification notification = new Notification(icon, "Custom Notification", when);

    NotificationManager mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification_custom_expanded_layout);
    contentView.setImageViewResource(R.id.image, R.drawable.ic_launcher);
    contentView.setTextViewText(R.id.notification_expanded_base_line_one, "Custom notification");
    contentView.setTextViewText(R.id.notification_expanded_base_line_two, "This is a custom layout");
    notification.contentView = contentView;

    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.contentIntent = contentIntent;

    notification.flags |= Notification.FLAG_NO_CLEAR; //Do not clear the notification
    notification.defaults |= Notification.DEFAULT_LIGHTS; // LED
    notification.defaults |= Notification.DEFAULT_VIBRATE; //Vibration
    notification.defaults |= Notification.DEFAULT_SOUND; // Sound

    mNotificationManager.notify(1, notification);

Но что я получаю, это:- Есть предложения?

0 ответов

Другие вопросы по тегам