Android:Notification之SmallIcon制作

 android5.0以上版本对Notification进行了改进,对于通知栏上的小图标不再支持五颜六色的png图像了,仅支持只有alpha通道的png图,还得只能用白色绘制。

  可以使用photoshop创建此种图像:

 

 

 

  • 步骤一:新建幅背景内容透明的RGB图像,并用白色画笔勾勒出图标的形状,
  • 步骤二:切换到通道面板中新建一个通道(默认就为alpha通道),然后关闭RGB通道,勾选Alpha1通道,
  • 步骤三:点击菜单栏文件-导出png图像,

这样导出的png图标可在Android5.0+版本显示,不会变成一个白框。勾勒图标时无论什么颜色,只打开alpha通道导出的png图在通知栏均为白色。


 activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button"/>

</RelativeLayout>

MainActivity.java

package com.example.sheep.firestone;

import android.app.Notification;
import android.app.NotificationManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    private Button button;
    private Notification notification;
    private NotificationManager notificationManager;
    private final int n_id = 1;

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

        button= this.<Button>findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                notificationManager.notify(n_id,notification);
            }
        });

        Bitmap bitmap=BitmapFactory.decodeResource(getResources(),R.drawable.timg003);
        notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        Notification.Builder nb=new Notification.Builder(this);
        nb.setSmallIcon(R.drawable.smallicon)
                .setLargeIcon(bitmap)
                .setContentTitle("System Alert")
                .setContentText("Code 001")
                .setPriority(Notification.PRIORITY_MAX);
        notification=nb.build();

    }
}

 



参考

https://blog.csdn.net/cqconelin/article/details/79583517 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android系统中,闹钟提醒结合通知是一种常见的功能,它可以让用户设置指定时间的闹钟,并在达到设定时间时通过通知进行提醒。 首先,用户可以通过系统提供的闹钟应用或其他支持闹钟功能的应用程序进行设置。用户可以选择特定的时间、重复日期和提醒模式来设置闹钟。一旦设置完成,系统会在设定的时间触发相应的闹钟事件。 当闹钟时间到达时,系统会弹出一个通知,通知栏上会显示闹钟提醒的相关信息,如闹钟标签、时间等。用户可以通过点击通知栏上的提醒来进入相应的应用程序或进行其他操作。 通知不仅可以在通知栏显示,还可以通过声音、震动或闪光等方式进行提醒。用户可以在系统设置中自定义闹钟提醒的方式。例如,用户可以选择只通过声音提醒、只通过震动提醒,或者同时使用声音和震动进行提醒。 通过闹钟提醒结合通知,用户可以方便地设置和管理自己的闹钟提醒,不再需要依赖传统的闹钟设备。而且,通过通知的形式进行提醒,用户可以更加及时地知道闹钟触发的信息,提高闹钟提醒的效果。 总而言之,Android系统提供了闹钟提醒结合通知的功能,用户可以通过设置闹钟来实现定时提醒,并在达到设定时间时通过通知进行提醒。这个功能方便实用,可以在日常生活和工作中帮助用户实时掌握时间。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值