Android,自定义通知,总是给我白色文本

Android, Custom Notification, Giving me always white Text

我正在尝试制作一个自定义通知栏,它可以正常工作,但是当我在棒棒糖中测试它时,它显示的是带有白色文本的标题和内容文本,这对 kitkat 很有用,因为通知栏是黑色的,但是不是棒棒糖。

我怎样才能让它变成默认颜色或至少检测操作栏的主题,这样我就可以做一个 if 语句来改变文本的颜色。

    <LinearLayout
        android:id="@+id/right"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:weightSum="1">

        <ImageView
            android:id="@+id/imagenotileft"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/ic_launcher"/>

        <RelativeLayout
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_width="0dp">
            <TextView
                android:id="@+id/title"
                android:textSize="18sp"
                android:textStyle="bold"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/white"
                android:hint="Title Text"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:layout_marginTop="10dp"/>

            <TextView
                android:id="@+id/text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/title"
                android:hint="Content Text"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"/>

        </RelativeLayout>

    <TextView
        android:id="@+id/space2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="        "
        android:layout_toLeftOf="@+id/right2"/>


        <RelativeLayout
            android:id="@+id/parentRa"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginRight="10dp"
            >


            <TextView
                android:id="@+id/time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:hint="12:12"
                android:text="12:12"
                />

            <ImageView
                android:id="@+id/imagenotiright"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/ic_action_chat"
                android:layout_below="@+id/time"
                android:nestedScrollingEnabled="false" />

        </RelativeLayout>
        </LinearLayout>
</RelativeLayout>

代码:

public void CustomNotification(String strtext) {
        // Using RemoteViews to bind custom layouts into Notification
        RemoteViews remoteViews = new RemoteViews(getPackageName(),
                R.layout.customnotification);

        // Set Notification Title
        String strtitle = getString(R.string.customnotificationtitle);
        // Open NotificationView Class on Notification Click
        Intent intent = new Intent(this, NotificationView.class);
        // Send data to NotificationView Class
        intent.putExtra("title", strtitle);
        intent.putExtra("text", strtext);
        intent.putExtra("String T", "");
        //intent.putExtra("Integer C", 0);

        // Open NotificationView.java Activity
        PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                // Set Icon
                .setSmallIcon(R.drawable.ic_launcher)
                        // Set Ticker Message
                .setTicker(getString(R.string.customnotificationticker))
                        // Dismiss Notification
                .setAutoCancel(true)
                        // Set PendingIntent into Notification
                .setContentIntent(pIntent)
                        // Set RemoteViews into Notification
                .setContent(remoteViews);

        // Locate and set the Image into customnotificationtext.xml ImageViews
        remoteViews.setImageViewResource(R.id.imagenotileft,R.drawable.ic_launcher);
        remoteViews.setImageViewResource(R.id.imagenotiright,R.mipmap.ic_action_chat);

        // Locate and set the Text into customnotificationtext.xml TextViews
        remoteViews.setTextViewText(R.id.title,getString(R.string.customnotificationtitle));
        remoteViews.setTextViewText(R.id.text, strtext);

        // Create Notification Manager
        NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        // Build Notification with Notification Manager
        notificationmanager.notify(0, builder.build());

    }

如有任何帮助,我将不胜感激。非常感谢。

我不是很确定,但你可以这样试试:

if (android.os.Build.VERSION.SDK_INT > 20) {
    // I am not sure of this method
    remoteViews.setTextColor(R.id.text, Color.WHITE);
}