Icon of notification in the Custom notification bar in the no-layout file of Android

Source: Internet
Author: User

Icon of notification in the Custom notification bar in the no-layout file of Android
When developing a project's functions related to the notification bar, the layout files available to the system cannot be introduced because your project is in the form of plug-ins, So that you cannot customize the layout, the icon in the notification bar cannot be customized. There is also a way to change the icon without layout files on the Internet. However, due to the openness of Android, some mobile phone manufacturers may modify the source code of the notification rather than using the original layout file method of the system. See the following article for more information: http://blog.csdn.net/z4244971432/article/details/10446715. To adapt to most models, a method of saving the nation is derived here... Public void show (String title, CharSequence content, Bitmap bitmap, PendingIntent intent) {// If the token with the same id is on the 2.3 host, if there is a ContentIntent without it, an exception _ notification will be thrown. setLatestEventInfo (_ context, "", "", null); _ notification. flags = _ flag; RemoteViews hide = _ notification. contentView; initView (_ notification, hide, title, content, intent, bitmap); _ manager. required y (_ 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 = n Otification. contentView. apply (_ context, null); // instantiate a View with notification, which is the layout view currently used by the system ViewGroup group = (ViewGroup) View; findView (group, new ViewVisitor () {@ Override public void onFindView (View item) {if (item instanceof ImageView) // find the ImageView under this layout is the icon control {bar. contentView. setInt (item. getId (), "setAlpha", 0); // hide the original icon. Because the icon set by the system in the Xiaomi system overwrites the original views. setViewPadding (item. getId (), item. getP AddingLeft (), item. getPaddingTop (), item. getPaddingRight (), item. getPaddingBottom (); if (bitmap! = Null) views. setImageViewBitmap (item. getId (), bitmap); // set the else views of the icon image. setImageViewResource (item. getId (), _ context. getApplicationInfo (). icon);} else if (item instanceof TextView) {views. setViewVisibility (item. getId (), View. GONE); // hide all textviews in the top view, which does not overlap with the bottom layer.}); views. setInt (view. getId (), "setBackgroundColor", Color. argb (0, 0, 0, 0); sets the background transparency of the Upper-layer layout views. setViewPadding (view. getId (), 0, View. getPaddingTop (), view. getPaddingRight (), view. getPaddingBottom (); bar. contentView. addView (view. getId (), views); // Add views to the original Layout View} public interface ViewVisitor {void onFindView (view View);} void findView (ViewGroup group, ViewVisitor visitor) // find all the subviews in the view {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) ;}} unable to accurately locate the custom layout, therefore, the icon and layout size in this mode may be slightly different from the original system style!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.