Android Nougat中通知栏中的彩色文本和图标
如何获得Twitter应用程序中的彩色文本和图标?在我的应用程序中,颜色显示为灰色和白色。。如何改变这个??Android Nougat中通知栏中的彩色文本和图标,android,android-layout,Android,Android Layout,如何获得Twitter应用程序中的彩色文本和图标?在我的应用程序中,颜色显示为灰色和白色。。如何改变这个?? 您可以在通知生成器上使用自定义的contentView 要定义自定义通知布局,请从实例化 RemoteViews对象,用于膨胀XML布局文件。然后,而不是 调用方法,如setContentTitle(),调用setContent()。设置 自定义通知中的内容详细信息,请使用中的方法 RemoteView可设置视图子级的值: 在单独的文件中为通知创建XML布局。你可以 使用任意文件名,但必
您可以在通知生成器上使用自定义的
contentView
要定义自定义通知布局,请从实例化
RemoteViews对象,用于膨胀XML布局文件。然后,而不是
调用方法,如setContentTitle(),调用setContent()。设置
自定义通知中的内容详细信息,请使用中的方法
RemoteView可设置视图子级的值:
在单独的文件中为通知创建XML布局。你可以
使用任意文件名,但必须在中使用扩展名.xml
在应用程序中,使用RemoteView方法定义通知的图标
和文本。将此RemoteViews对象放入
通过调用setContent()调用NotificationCompat.Builder。避免设置
可在RemoteView对象上绘制背景,因为您的文本
颜色可能变得不可读
代码如下:
RemoteViews mycontentView = new RemoteViews(getPackageName(), R.layout.notification);
mycontentView.setImageViewResource(R.id.myimage, R.mipmap.ic_launcher);
mycontentView.setTextViewText(R.id.mytitle, "Custom Notification");
NotificationCompat.Builder myBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.icon)
.setContent(mycontentView);
Notification myNotification = myBuilder.build();
myNotification.flags |= Notification.FLAG_AUTO_CANCEL;
myNotification.defaults |= Notification.DEFAULT_SOUND;
myNotification.defaults |= Notification.DEFAULT_VIBRATE;
myNotificationManager.notify(1, myNotification);
其中R.layout.notification
是您的自定义布局文件
布局文件在下面
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="64dp"
android:padding="12dp" >
<ImageView
android:src="@mipmap/ic_launcher"
android:id="@+id/myimage"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp" />
<TextView
android:textSize="12dp"
android:textColor="#000"
android:text="Testing"
android:id="@+id/mytitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/myimage"
/>
</RelativeLayout>
我希望有帮助 您可以在通知生成器上使用自定义的
contentView
要定义自定义通知布局,请从实例化
RemoteViews对象,用于膨胀XML布局文件。然后,而不是
调用方法,如setContentTitle(),调用setContent()。设置
自定义通知中的内容详细信息,请使用中的方法
RemoteView可设置视图子级的值:
在单独的文件中为通知创建XML布局。你可以
使用任意文件名,但必须在中使用扩展名.xml
在应用程序中,使用RemoteView方法定义通知的图标
和文本。将此RemoteViews对象放入
通过调用setContent()调用NotificationCompat.Builder。避免设置
可在RemoteView对象上绘制背景,因为您的文本
颜色可能变得不可读
代码如下:
RemoteViews mycontentView = new RemoteViews(getPackageName(), R.layout.notification);
mycontentView.setImageViewResource(R.id.myimage, R.mipmap.ic_launcher);
mycontentView.setTextViewText(R.id.mytitle, "Custom Notification");
NotificationCompat.Builder myBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.icon)
.setContent(mycontentView);
Notification myNotification = myBuilder.build();
myNotification.flags |= Notification.FLAG_AUTO_CANCEL;
myNotification.defaults |= Notification.DEFAULT_SOUND;
myNotification.defaults |= Notification.DEFAULT_VIBRATE;
myNotificationManager.notify(1, myNotification);
其中R.layout.notification
是您的自定义布局文件
布局文件在下面
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="64dp"
android:padding="12dp" >
<ImageView
android:src="@mipmap/ic_launcher"
android:id="@+id/myimage"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp" />
<TextView
android:textSize="12dp"
android:textColor="#000"
android:text="Testing"
android:id="@+id/mytitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/myimage"
/>
</RelativeLayout>
我希望有帮助 以下是一种更简单、更简短的方法:
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setColor(ContextCompat.getColor(context, R.color.primary));
查阅参考资料。干杯 以下是一种更简单、更简短的方法:
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setColor(ContextCompat.getColor(context, R.color.primary));
查阅参考资料。干杯