第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

創(chuàng)建自定義通知,Android

創(chuàng)建自定義通知,Android

不負(fù)相思意 2019-10-11 10:31:30
我想創(chuàng)建一個(gè)類(lèi)似于該圖像中帶有紅色邊框的通知的通知:我知道如何創(chuàng)建正常的通知,例如此圖像中帶有藍(lán)色邊框的通知,但是我想顯示一個(gè)圖標(biāo),以及附近的三行信息。我怎樣才能做到這一點(diǎn)?任何建議將不勝感激。
查看完整描述

2 回答

?
拉風(fēng)的咖菲貓

TA貢獻(xiàn)1995條經(jīng)驗(yàn) 獲得超2個(gè)贊

添加RemoteViews通知。這是一個(gè)示例:

http://img1.sycdn.imooc.com//5d9fe9a90001bfca04750200.jpg

var remoteViews = new RemoteViews(getPackageName(), R.layout.widget);

var 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);


var notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);


// mId allows you to update the notification later on.

notificationManager.notify(100, mBuilder.build()); 

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> 

檢查這篇文章還有更多的樣式可供選擇


Android開(kāi)發(fā)人員


編輯:

NotificationCompat.Builder是在所有Android版本上創(chuàng)建通知的最簡(jiǎn)單方法。您甚至可以使用Android 4.1可用的功能。如果您的應(yīng)用程序在Android> = 4.1的設(shè)備上運(yùn)行,則將使用新功能;如果在Android <4.1的設(shè)備上運(yùn)行,則通知將是簡(jiǎn)單的舊通知。


對(duì)于<11 API,請(qǐng)使用http://www.framentos.com/zh-CN/android-tutorial/2012/02/20/how-to-create-a-custom-notification-on-android/


查看完整回答
反對(duì) 回復(fù) 2019-10-11
?
縹緲止盈

TA貢獻(xiàn)2041條經(jīng)驗(yàn) 獲得超4個(gè)贊

從Android 4.1開(kāi)始,可以使用擴(kuò)展的通知來(lái)處理這些情況。如果您使用Notification.Builder或NotificationCompat.Builder,則可以使用或其他樣式之一為展開(kāi)的通知設(shè)置普通樣式和Builder單獨(dú)樣式,然后將兩者連接起來(lái)。BuilderNotificationCompat.InboxStyle


查看完整回答
反對(duì) 回復(fù) 2019-10-11
  • 2 回答
  • 0 關(guān)注
  • 506 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)