gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 01:33:36 25 4
gpt4 key购买 nike

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

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

enter image description here

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

关于Android,自定义通知,总是给我白色文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29904407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com