通知的综合应用

来源:互联网 发布:梅西c罗数据对比最新 编辑:程序博客网 时间:2024/05/08 14:25

1.取消通知

创建的时候调用setAuthCancek(true),用户点击自动消失,多好

  • The user dismisses the notification either individually or by using "Clear All" (if the notification can be cleared).
  • The user clicks the notification, and you called setAutoCancel() when you created the notification.
  • You call cancel() for a specific notification ID. This method also deletes ongoing notifications.
  • You call cancelAll(), which removes all of the notifications you previously issued.     

Preserving Navigation when Starting an Activity

启动一个新的活动,要能导航,这个,还不太明白,需要进一步学习?

 

最后自定义布局:

定义个布局文件:ImageView的background没法用颜色啊,为什么

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:background="#545454" 
                android:gravity="center_horizontal">


    <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/codeversed_logo"
            android:contentDescription="@string/codeversed_logo"/>


    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>


</LinearLayout>


// Creates an explicit intent for an ResultActivity to receive.
Intent resultIntent = new Intent(this, ResultActivity.class);


// This ensures that the back button follows the recommended
// convention for the back key.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);


// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(ResultActivity.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);


// Create remote view and set bigContentView.
RemoteViews expandedView = new RemoteViews(this.getPackageName(), 
        R.layout.notification_custom_remote);
expandedView.setTextViewText(R.id.text_view, "Neat logo!");


Notification notification = new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.ic_launcher)
        .setAutoCancel(true)
        .setContentIntent(resultPendingIntent)
        .setContentTitle("Custom View").build();


notification.bigContentView = expandedView;

0 0
原创粉丝点击