benshiqiao676 2016-10-19 18:48 采纳率: 21.1%
浏览 5387
已结题

android 5.0版本后Notification通知栏的大小图标问题

要求系统版本在5.0之后,而且程序的targetSDK也是大于21,不修改这两个地方的情况下把图里红圈的地方去掉,我试过用NotificationCompat,没有用和Notification的情况是一样的

先上代码

 package com.example.notificationtest;

import android.app.Activity;
import android.app.Notification;
import android.app.Notification.Builder;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        showNotification2();
        showNotification();
        showNotification3();
    }



    protected void showNotification2() {  
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);  
        Builder builder = new Notification.Builder(this);  
        PendingIntent contentIndent = PendingIntent.getActivity(MainActivity.this, 0, new Intent(MainActivity.this,MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);  
        builder.setContentIntent(contentIndent) .setSmallIcon(R.drawable.icon_notification)//设置状态栏里面的图标(小图标)                     .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.i5))//下拉下拉列表里面的图标(大图标)        .setTicker("this is bitch!") //设置状态栏的显示的信息  
               .setWhen(System.currentTimeMillis())//设置时间发生时间  
               .setAutoCancel(true)//设置可以清除  
               .setContentTitle("This is ContentTitle")//设置下拉列表里的标题  
               .setContentText("this is ContentText");//设置上下文内容  

        Notification notification = builder.getNotification();  
        //加i是为了显示多条Notification  
        notificationManager.notify(12121,notification);  
    }  

    private void showNotification(){
        NotificationCompat.Builder buider = new android.support.v4.app.NotificationCompat.Builder(this)
                 .setContentTitle("123")
                 .setContentText("456")
                 .setSmallIcon(R.drawable.icon_notification)
                 .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.icon_notification))
                 .setAutoCancel(true);//设置可以清除  

         NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);  
         notificationManager.notify(12122,buider.getNotification());  
    }

    private void showNotification3(){
        Notification.Builder builder = new Notification.Builder(this);
        builder.setContentTitle("横幅通知");
        builder.setContentText("这是一个横幅通知");
        builder.setDefaults(NotificationCompat.DEFAULT_ALL);
        builder.setSmallIcon(R.drawable.icon_notification);
        builder.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.icon_notification));
        Intent intent = new Intent(this,MainActivity.class);
        PendingIntent pIntent = PendingIntent.getActivity(this,1,intent,0);
        builder.setContentIntent(pIntent);
        builder.setFullScreenIntent(pIntent,true);
        builder.setAutoCancel(true);
        Notification notification = builder.build();
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(12113,notification);
    }

}

图片说明

图片说明

  • 写回答

2条回答 默认 最新

  • 东风玖哥 2016-10-20 06:07
    关注

    你只要不setSmallIcon就行了

    评论

报告相同问题?

悬赏问题

  • ¥15 SQL Server下载
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求