2

Android アプリケーションでカスタム通知を作成しようとしています。次のコードを使用しています

カスタム レイアウト

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/custom_notification"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"

    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="50dp"
        android:layout_height="fill_parent"
        android:background="@drawable/notification_background"
        android:clickable="true" >

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="@drawable/ic_action_test" />
    </LinearLayout>
</LinearLayout>

これが私の通知の作成方法です

RemoteViews contentView = new RemoteViews(activity.getPackageName(), R.layout.notification);

            Notification noti = new NotificationCompat.Builder(activity)

                    .setSmallIcon(R.drawable.ic_launcher)
                    .build();
            noti.contentView = contentView;
            // Hide the notification after its selected
            noti.flags |= Notification.FLAG_NO_CLEAR;

            notificationManager.notify(0, noti);

通知が作成されますが、高さ属性に fill_parent を使用しているにもかかわらず、通知バーの高さ全体をカバーしていません。

ここで何が悪いのか誰か教えてもらえますか?

4

1 に答える 1

1

手遅れですが、私を助けてくれました。透明なxmlまたはpngで背景画像を作成し(必要に応じて色を付けることができます)、背景画像の高さは通知の高さよりも長くする必要があります。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/custom_notification"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/tran"
    android:orientation="horizontal" >
    <LinearLayout
        android:layout_width="50dp"
        android:layout_height="fill_parent"
        android:background="@drawable/notification_background"
        android:clickable="true" >
        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="@drawable/ic_action_test" />
    </LinearLayout>
</LinearLayout>

tran.xml

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@android:color/transparent"/>
    <size android:width="400dp" android:height="400dp"/>
</shape>
于 2015-01-05T18:52:10.467 に答える