博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
实现自定义布局的Notification
阅读量:2391 次
发布时间:2019-05-10

本文共 1893 字,大约阅读时间需要 6 分钟。

     上一节中,我们实现了自己的notification,相信大家都有了一些认识,在最后也接受了利用RemoteView来实现自定义布局的notification,这里就来举一个示例,方便理解。

      第一步:新建一个工程,命名为cusNotification;

      第二步:新建一个布局文件(即自定义的notification的布局文件:custom_notification.xml,内容如下:

          第三步:新建上面布局文件中引用到的styyes.xml文件,代码如下:

       第四步:修改java源文件,代码如下:

public class CusNotificationActivity extends Activity {	private static final int CUSTOM_VIEW_ID = 1;    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);                //Notification notification = new Notification();        int icon = R.drawable.ic_launcher;        CharSequence tickerText = "Notification01";        long when = System.currentTimeMillis();        Notification notification = new Notification(icon, tickerText, when);                RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification);        contentView.setImageViewResource(R.id.image, R.drawable.notification_image);        contentView.setTextViewText(R.id.title, "Custom notification");        contentView.setTextViewText(R.id.text, "This is a custom layout");        notification.contentView = contentView;                Intent notificationIntent = new Intent(this, CusNotificationActivity.class);        PendingIntent contentIntent = PendingIntent.getActivity(CusNotificationActivity.this, 0, notificationIntent, 0);        notification.contentIntent = contentIntent;                String ns = Context.NOTIFICATION_SERVICE;        NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);        mNotificationManager.notify(CUSTOM_VIEW_ID, notification);    }}
          第五步:运行程序,看看再notifications window中出现的效果如下:

           当然,我们这里还和默认的布局效果做一下对比,下面的是使用默认的布局的效果图:

        这里主要是讲解自定义布局notification的实现,并没有做出很炫的效果!就到这吧!

转载地址:http://dvqab.baihongyu.com/

你可能感兴趣的文章
WASC Distributed Web Honeypots Project Update
查看>>
安装pydev到eclipse
查看>>
[WAF]apache和modsecurity的安装
查看>>
写给换工作和找工作的同学
查看>>
Island Hopping the SpiderLabs Way
查看>>
Top Ten Web Protection Techniques of 2011
查看>>
Faster Blind MySQL Injection Using Bit Shifting
查看>>
Safely Dumping Hashes from Live Domain Controllers
查看>>
sgx模拟器
查看>>
SGX相关资源
查看>>
nessus 购买地址
查看>>
Google Security Architecture
查看>>
web server信息收集(附带plesk xday)
查看>>
JBoss AS Administrative Console Password Disclosure
查看>>
Securely Developing on Mobile
查看>>
ModSecurity Updates: Nginx Stable Release and Google Summer of Code Participation
查看>>
Java Web 三层架构详解
查看>>
iphone for PPT遥控器 MyPoint PowerPoint Remote
查看>>
ZPanel 10.0.0.2 Remote Command Execution
查看>>
Using Mimikatz Alpha or Getting Clear Text Passwords with a Microsoft Tool
查看>>