本文介绍了创建自定义通知,机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个喜欢红色边框的通知,在这个形象的通知:

I want to create a notification that like the red bordered notification in this image:

我知道如何创建像在此图像中蓝色边框的通知正​​常通知,但我想说明的图标和近,大约3行信息。我该怎么办呢?任何建议将AP preciated。

I know how to create normal notifications like the blue bordered notifications in this image, but I want to show an icon and about 3 lines of information near that. How can I do that? Any suggestion will be appreciated.

推荐答案

在通知中添加远程视​​窗下面是示例

add RemoteView in notification Here is Sample

RemoteViews remoteViews = new RemoteViews(getPackageName(),
                     R.layout.widget);
           NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                     this).setSmallIcon(R.drawable.ic_launcher).setContent(
                     remoteViews);
           // Creates an explicit intent for an Activity in your app
           Intent resultIntent = new Intent(this, test.class);
           // The stack builder object will contain an artificial back stack for
           // the
           // started Activity.
           // This ensures that navigating backward from the Activity leads out of
           // your application to the Home screen.
           TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
           // Adds the back stack for the Intent (but not the Intent itself)
           stackBuilder.addParentStack(test.class);
           // Adds the Intent that starts the Activity to the top of the stack
           stackBuilder.addNextIntent(resultIntent);
           PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                     PendingIntent.FLAG_UPDATE_CURRENT);
           remoteViews.setOnClickPendingIntent(R.id.button1, resultPendingIntent);
           NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
           // mId allows you to update the notification later on.
           mNotificationManager.notify(100, mBuilder.build());

widget.xml

widget.xml

<?xml version="1.0" encoding="UTF-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:gravity="center"
   android:orientation="horizontal" >
   <TextView
     android:id="@+id/textView1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:gravity="center"
     android:text="DJ notification"
     android:textAppearance="?android:attr/textAppearanceMedium" />
   <Button
     android:id="@+id/button1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="Close Me" />
 </LinearLayout>

检查这文章有更多的风格avaialbe

check this article there is more style avaialbe

Android开发者

的NotificationCompat.Builder是最简单的方法来创建所有的Andr​​oid版本的通知。你甚至可以使用的功能,可与Android 4.1。如果您的应用程序与Android设备上运行> = 4.1的新功能将被使用,如果运行在Android&LT; 4.1通知将是一个简单的老的通知

有关&LT; 11 API使用http://www.framentos.com/en/android-tutorial/2012/02/20/how-to-create-a-custom-notification-on-android/

for < 11 API use http://www.framentos.com/en/android-tutorial/2012/02/20/how-to-create-a-custom-notification-on-android/

这篇关于创建自定义通知,机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 06:28