日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁(yè) > 嵌入式 > 嵌入式軟件
[導(dǎo)讀] 在開(kāi)發(fā)項(xiàng)目一個(gè)與通知欄有關(guān)的功能時(shí),由于自己的項(xiàng)目是基于插件形式的所以無(wú)法引入系統(tǒng)可用的布局文件,這樣無(wú)法自定義布局,造成無(wú)法自定義通知欄的icon。在網(wǎng)上也有一種

 在開(kāi)發(fā)項(xiàng)目一個(gè)與通知欄有關(guān)的功能時(shí),由于自己的項(xiàng)目是基于插件形式的所以無(wú)法引入系統(tǒng)可用的布局文件,這樣無(wú)法自定義布局,造成無(wú)法自定義通知欄的icon。

在網(wǎng)上也有一種不用布局文件更換icon的方法,但是由于Android的開(kāi)放性,某些手機(jī)廠(chǎng)商會(huì)修改通知的源碼,不是使用系統(tǒng)原有的布局文件方法有一定的局限性。文章如下http://blog.csdn.net/z1074971432/article/details/10446715有興趣的朋友可以看下。

為了適配大多數(shù)的機(jī)型這里衍生出一種比較曲線(xiàn)救國(guó)的方式。。。

public void show(String title, CharSequence content, Bitmap bitmap, PendingIntent intent)

{

// 在2.3的機(jī)子上,如果id相同的notifation,有一個(gè)帶ContentIntent一個(gè)不帶就會(huì)拋異常

_notification.setLatestEventInfo(_context, "", "", null);

_notification.flags = _flag;

RemoteViews hide = _notification.contentView;

initView(_notification,hide, title, content, intent,bitmap);

_manager.notify(_id, _notification);

}

public void cancel()

{

_manager.cancel(_id);

}

@SuppressWarnings("deprecation")

void initView(final Notification bar, final RemoteViews views, String title, CharSequence text, PendingIntent intent, final Bitmap bitmap)

{

bar.contentView = null;

bar.setLatestEventInfo(_context, title, text, intent);

Notification notification = new Notification();

notification.setLatestEventInfo(_context, "", "", null);

View view = notification.contentView.apply(_context, null);//以notification實(shí)例化一個(gè)View,這個(gè)就是系統(tǒng)當(dāng)前使用的布局視圖

ViewGroup group = (ViewGroup) view;

findView(group, new ViewVisitor()

{

@Override

public void onFindView(View item)

{

if (item instanceof ImageView)//查找這個(gè)布局下的ImageView就是icon控件

{

bar.contentView.setInt(item.getId(), "setAlpha", 0);//將原有的icon隱藏,由于在小米系統(tǒng)中系統(tǒng)設(shè)置的icon會(huì)覆蓋原有設(shè)置的

views.setViewPadding(item.getId(), item.getPaddingLeft(), item.getPaddingTop(), item.getPaddingRight(), item.getPaddingBottom());

if (bitmap != null)

views.setImageViewBitmap(item.getId(), bitmap);//設(shè)置icon圖片

else views.setImageViewResource(item.getId(), _context.getApplicationInfo().icon);

}

else if(item instanceof TextView)

{

views.setViewVisibility(item.getId(), View.GONE);//隱藏最上層的view里的所有的TextView,不與底層的重疊

}

}

});

views.setInt(view.getId(), "setBackgroundColor", Color.argb(0, 0, 0, 0));設(shè)置上層布局的背景透明

views.setViewPadding(view.getId(), 0, view.getPaddingTop(), view.getPaddingRight(), view.getPaddingBottom());

bar.contentView.addView(view.getId(), views);//將views添加到原有的布局視圖上

}

public interface ViewVisitor

{

void onFindView(View view);

}

void findView(ViewGroup group, ViewVisitor visitor)//查找視圖里面的所有子視圖

{

for (int i = 0; i < group.getChildCount(); i++)

{

View view = group.getChildAt(i);

if (visitor != null)

visitor.onFindView(view);

if (view instanceof ViewGroup)

findView((ViewGroup) view, visitor);

}

}

由于無(wú)法對(duì)自定義的布局進(jìn)行準(zhǔn)確定位,所以這種方式的icon和布局大小與原有系統(tǒng)樣式可能有一點(diǎn)偏差!

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專(zhuān)欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉