NotificationCompat android - how to show only Large icon without small

后端 未结 5 1708
轻奢々
轻奢々 2021-01-04 10:59

When I add notification:

        NotificationCompat.Builder mBuilder =
                            new NotificationCompat.Builder(this)  
              .set         


        
相关标签:
5条回答
  • 2021-01-04 11:18

    You can create a custom notification and then show whatever you want in the large notification area. See and example here TutorialsFace: Build all types of Notifications in Android

    0 讨论(0)
  • 2021-01-04 11:22
    public class MainActivity extends AppCompatActivity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Notification notification = new NotificationCompat.Builder(this)
                .setContentTitle("Test")
                .setContentText("Hii There")
                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.smallicon))
                .setAutoCancel(true)
                .build();
        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
        notificationManager.notify(123, notification);
      }
    }
    
    0 讨论(0)
  • 2021-01-04 11:29

    get the small icon id and then try to hide it

    int smallIconId = ctx.getResources().getIdentifier("right_icon", "id", android.R.class.getPackage().getName());
    if (smallIconId != 0) { 
        if (notification.contentView!=null)
            notification.contentView.setViewVisibility(smallIconId, View.INVISIBLE);
    }
    

    try looking at this post it will help too

    i test the code on api 18,23 (samsung j1,galaxy S6) work fine

    0 讨论(0)
  • 2021-01-04 11:31

    Small icon is mandatory. If you don't set a large one you'll get your small icon bigger in the middle of the circle with the color of your choice (setColor).

    If i were you i'd put that blank E on a transparent background for smallicon, and set a red color for the circle.

    0 讨论(0)
  • 2021-01-04 11:35

    Based on the previous answer you can also hide the expended view too :

    int smallIconId = AnghamiApp.getContext().getResources().getIdentifier("right_icon", "id", android.R.class.getPackage().getName());
                if (smallIconId != 0) {
                    notification.contentView.setViewVisibility(smallIconId, View.INVISIBLE);
                    notification.bigContentView.setViewVisibility(smallIconId, View.INVISIBLE);
                }
    
    0 讨论(0)
提交回复
热议问题