欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

如何自定義狀態(tài)欄notification布局

這篇文章主要介紹如何自定義狀態(tài)欄notification布局,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

十多年的銅官網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。營(yíng)銷型網(wǎng)站建設(shè)的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整銅官建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)公司從事“銅官網(wǎng)站設(shè)計(jì)”,“銅官網(wǎng)站推廣”以來,每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。

布局定義custom_notification.xml

<?xml version="1.0" encoding="utf-8"?>  
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent" >  
      
    <ImageView   
        android:id="@+id/p_w_picpath"  
        android:layout_width="wrap_content"  
        android:layout_height="fill_parent"  
        android:layout_alignParentLeft="true"  
        android:layout_marginRight="10dp"  
        android:contentDescription="@string/Image" />  
      
    <TextView   
        android:id="@+id/title"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:layout_toRightOf="@id/p_w_picpath"  
         />  
      
    <TextView   
        android:id="@+id/text"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:layout_toRightOf="@id/p_w_picpath"  
        android:layout_below="@id/title"  
         />  
      
</RelativeLayout>

布居中引用的樣式文件styles.xml

<?xml version="1.0" encoding="utf-8"?>  
<resources>  
<style name="NotificationText" parent="android:TextAppearance.StatusBar.EventContent" />  
<style name="NotificationTitle" parent="android:TextAppearance.StatusBar.EventContent.Title" />  
</resources>

代碼

package cn.itcast.tabhost;



import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.Color;
import android.widget.RemoteViews;

public  class FirstActivity extends Activity  {
    
    //默認(rèn)點(diǎn)擊返回鍵(back)會(huì)finish當(dāng)前activity
    //activity棧中的所有activity都彈出后會(huì)退出當(dāng)前應(yīng)用
    @Override
    public void onBackPressed() {
        
        /*
         * 按照一般的邏輯,當(dāng)Activity棧中有且只有一個(gè)Activity時(shí),當(dāng)按下Back鍵此
         * 那么下次點(diǎn)擊此應(yīng)用程序圖標(biāo)將從重新啟動(dòng),當(dāng)前不少應(yīng)用程序都是采取如Home鍵的效果,
         * 當(dāng)點(diǎn)擊了Back鍵,系統(tǒng)返回到桌面,然后點(diǎn)擊應(yīng)用程序圖標(biāo)
         * 直接回到之前的Activity界面,這種效果是怎么實(shí)現(xiàn)的呢?通過重寫按下Back鍵的回調(diào)函數(shù),轉(zhuǎn)成Home鍵的效果即可。
         */
        // 改為使用intent啟動(dòng)HOME桌面
        Intent home = new Intent(Intent.ACTION_MAIN);
        home.addCategory(Intent.CATEGORY_HOME);
        startActivity(home);

        // 或者,為達(dá)到此類效果,Activity實(shí)際上提供了直接的方法。
        // 將當(dāng)前Activity所在的Task移到后臺(tái),同時(shí)保留activity順序和狀態(tài)。
        moveTaskToBack(true);// true表示不管是不是根都有效
    }
    
    
        /**
         * 當(dāng)此Activity處于后臺(tái)工作時(shí), 在狀態(tài)欄顯示通知
         */
        @Override
        protected void onStop() {
            showNotification();
            super.onStop();
        }
    
    //當(dāng)程序再次進(jìn)入運(yùn)行界面時(shí),Activity處于onResume狀態(tài),在onResume方法中去掉狀態(tài)欄的程序運(yùn)行信息即可
    
        /**
         * 此Activity啟動(dòng)后關(guān)閉狀態(tài)欄的通知
         */
        @Override
        protected void onResume() {
            // 啟動(dòng)后刪除之前我們定義的通知
            NotificationManager notificationManager = (NotificationManager) this
                    .getSystemService(NOTIFICATION_SERVICE);
            notificationManager.cancel(CUSTOM_VIEW_ID);
            super.onResume();
        }
        
        private static final int CUSTOM_VIEW_ID = 1; 
      //在狀態(tài)欄顯示程序通知
        private void showNotification() {
            // 創(chuàng)建一個(gè)NotificationManager的引用
            NotificationManager notificationManager = (NotificationManager) this
                    .getSystemService(android.content.Context.NOTIFICATION_SERVICE);
    
            // 定義Notification的各種屬性
            Notification notification = new Notification(R.drawable.bg_normal,
                    "superGao", System.currentTimeMillis());
            
            
            
            RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification); 
            contentView.setImageViewResource(R.id.p_w_picpath, R.drawable.i1);  
            contentView.setTextViewText(R.id.title, "自定義布局通知標(biāo)題");  
            contentView.setTextViewText(R.id.text, "自定義布局通知內(nèi)容"); 
            //給view設(shè)置點(diǎn)擊事件
       /*     contentView.setOnClickPendingIntent(viewId, pendingIntent);
            */
            
            notification.contentView = contentView; 
            
            notification.flags |= Notification.FLAG_ONGOING_EVENT; // 將此通知放到通知欄的"Ongoing"即"正在運(yùn)行"組中
            notification.flags |= Notification.FLAG_NO_CLEAR; // 表明在點(diǎn)擊了通知欄中的"清除通知"后,此通知不清除,經(jīng)常與FLAG_ONGOING_EVENT一起使用
            notification.flags |= Notification.FLAG_SHOW_LIGHTS;//使用LED燈
            notification.defaults = Notification.DEFAULT_LIGHTS;
            notification.ledARGB = Color.BLUE;//LED燈顏色
            notification.ledOnMS = 5000;//led燈持續(xù)時(shí)間
    
            // 設(shè)置通知的事件消息
            /*
             * CharSequence contentTitle = "superGao"; // 通知欄標(biāo)題
                CharSequence contentText = "love"; // 通知欄內(nèi)容
            */
            Intent notificationIntent = new Intent(this, FirstActivity.class); // 點(diǎn)擊該通知后要跳轉(zhuǎn)的Activity
            PendingIntent contentItent = PendingIntent.getActivity(this, 0,
                    notificationIntent, 0);
            notification.contentIntent=contentItent;
            
           /* notification.setLatestEventInfo(this, contentTitle, contentText,
                    contentItent);*/
    
            // 把Notification傳遞給NotificationManager
            notificationManager.notify(CUSTOM_VIEW_ID , notification);
    
        }
    
}

以上是“如何自定義狀態(tài)欄notification布局”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

當(dāng)前標(biāo)題:如何自定義狀態(tài)欄notification布局
網(wǎng)頁(yè)網(wǎng)址:http://chinadenli.net/article22/geoccc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁(yè)設(shè)計(jì)公司App開發(fā)網(wǎng)站策劃網(wǎng)站改版網(wǎng)站導(dǎo)航定制開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

微信小程序開發(fā)