Android的:如何创建自定义通知和编程编辑其布局添加视图? [英] Android: How to create a custom notification and edit its layout adding views programmatically?

查看:242
本文介绍了Android的:如何创建自定义通知和编程编辑其布局添加视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何创建一个自定义通知和编辑是布局添加视图编程,允许用户定制的通知。

I'd like to know how to create a custom notification and edit is layout adding views programmatically to allow user to customize is notification.

我不能做的是这样的:

如果我创建一个自定义的LinearLayout是这样的:

If I create a custom LinearLayout like this:

LinearLayout ll = new LinearLayout(c);
ImageView iv = new ImageView(c);
iv.setImageResource(R.drawable.bt_close);
ll.addView(iv);

我如何使用此布局创建一个通知,并添加一个动作,当我点击的ImageView办?

How I can create a notification using this layout and add an action to do when I click on ImageView?

在code键使自定义通知仅仅是这个?

The code to make a custom notification is only this?

Notification notification = (statusIcon, appName, System.currentTimeMillis());
notification.contentView = new RemoteViews(this.getPackageName(),R.layout.notification);

非常感谢在所有...

Many thanks at all...

推荐答案

通知区域中使用 RemoteViews 就像Android应用程序的窗口小部件。

Notification area uses RemoteViews just like Android App Widgets.

他们不喜欢你的应用程序UI部件。你必须引用它们,你可以创建他们,但他们居住在其他应用程序。 (通知UI是系统应用程序,应用程序部件是在家庭桌面应用。)

They are not like the UI parts in your application. You have reference to them, you can create them but they reside in other apps. (Notifications' UI is in System app, and app widgets is in Home Launcher app.)

由于他们是不是真的在你的应用中显示,你不能直接访问它们。你不能例如设置 onClickListener

Since they are not really shown in your app, you cannot directly access them. You cannot set onClickListener for example.

这就是为什么我们有 RemoteViews

That's why we have RemoteViews.

使用它们,您可以定义如何通过给布局文件和一些内置的功能来改变文字,图像等创建它们,并且你给的PendingIntent 来一个按钮被点击时被解雇。而已。

With them, you can define how to create them by giving the layout file and some built-in functions to change the text, image etc. And you give PendingIntent to be fired when a button is clicked. That's it.

在结束时,你实际上可以更改UI在通知动态而不是你通常做在您的应用程序的方式。

In the end, you can actually change the UI in your notification dynamically but not the way you usually do in your app.

您可以看到这个答案如何创建一个。
<一href=\"http://stackoverflow.com/a/21283668/1016462\">http://stackoverflow.com/a/21283668/1016462

You can see this answer for how to create one. http://stackoverflow.com/a/21283668/1016462

这篇关于Android的:如何创建自定义通知和编程编辑其布局添加视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆