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 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀