Android,自定义通知,始终给我白色文本 [英] Android, Custom Notification, Giving me always white Text

查看:71
本文介绍了Android,自定义通知,始终给我白色文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图制作一个自定义的通知栏,它可以正常工作,但是当我在棒棒糖中对其进行测试时,它会显示带有白色文本的标题和内容文本,这对kitkat很有好处,因为通知栏很暗,但不适用于棒棒糖.

I am trying to make a custom notification bar, it works and all but when i test it in lollipop it's displaying the title and content text with white color text, it is good for kitkat because the notification bar is dark but not for lollipop.

我如何使其更改为默认颜色或至少检测操作栏的主题,以便我可以执行if语句来更改文本的颜色.

How can i make it change to default color or at least detect the theme of the action bar so i can make an if statement to change the color of the text.

    <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());

    }

我将不胜感激.非常感谢.

I would appreciate any help. Thank you so much.

推荐答案

我不太确定,但是您可以尝试执行以下操作:

I am not very sure, but you can try something like this:

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

这篇关于Android,自定义通知,始终给我白色文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆