[英]Little Symbol in Notification Icon
有人可以告訴我如何擺脫通知圖標中的小符號嗎?
Bitmap icon = BitmapFactory.decodeResource(mainact.getResources(),R.mipmap.ic_launcher);
Notification notification = new NotificationCompat.Builder(mainact, "Channel1")
.setLargeIcon(icon)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("NotifyBlock")
.setContentText("All notifications are blocked.")
.setOngoing(true)
.build();
notificationManager.notify(1, notification);
我認為是帶有徽章的自定義通知布局。
你應該這樣做:
創建新布局 custom_push.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="72dp"
android:padding="10dp" >
<FrameLayout
android:id="@+id/frame"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<ImageView
android:src="@mipmap/ic_launcher"
android:id="@+id/image"
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="8dp" />
<ImageView
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="@android:drawable/btn_star"
android:layout_gravity="bottom|end"
android:tint="@color/colorAccent"
android:layout_width="16dp"
android:layout_height="16dp"/>
</FrameLayout>
<TextView
android:textSize="13dp"
android:textColor="#000"
android:text="Testing"
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/frame"
/>
<TextView
android:textSize="13dp"
android:textColor="#000"
android:text="Testing is awecome"
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/frame"
android:layout_below="@id/title"
/>
</RelativeLayout>
下一步需要時調用此方法:
private void showNotification() {
String CHANNEL_ID = "ChannelID";
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String descriptionText = "Notification Channel";
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_ID, NotificationManager.IMPORTANCE_DEFAULT);
channel.setDescription(descriptionText);
// Register the channel with the system
notificationManager.createNotificationChannel(channel);
}
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_push);
contentView.setImageViewResource(R.id.image, R.mipmap.ic_launcher);
contentView.setTextViewText(R.id.title, "Custom notification");
contentView.setTextViewText(R.id.text, "This is a custom layout");
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_push_icon)
.setContent(contentView);
Notification notification = mBuilder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(1, notification);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.