Skip to main content

Custom Notification View


I would like to create a notification icon view that looks similar to the Google+ app's notification. The difference will be that I need to be able to change the color at runtime where as the Google+ icons gray or red so I'm assuming they are using a StateListDrawable.



What is the best approach for this? I'd prefer to have the rounded clipped corners and have the option to have a drawable inside. This custom view will be placed in the Action Bar as well. I still need the view to respond to android:background state list drawables so I can have the click and selected accordance working.



This custom view will be placed in the action bar as well.



Google+ app with the notification icon in the upper right that's grayed out and has a 0 in the middle.


Source: Tips4all
Source: Tips4allSource: CCNA FINAL EXAM

Comments

  1. I solved this by doing the following.

    Created this to make the rounded corner shape with a solid color. This also adds a translucent black to give it a pressed look against a blackground.
    res/drawable/shape_notification.xml

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <stroke android:color="#33000000" android:width="2dp"/>
    <corners android:radius="4dp" />
    <solid android:color="#99333333"/>
    </shape>


    The layer drawable will be used as the actual drawable on the action bar item. It has the background (written above) overlayed with the wrench icon.
    res/drawable/layer_customizer.xml

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:drawable="@drawable/shape_notification" />
    <item android:drawable="@drawable/ic_menu_preferences" />
    </layer-list>


    Java code to change the color. The target view is the object that is assigned the layer_customizer drawable. The color passed in will change the shape_notification.xml's solid tag color.

    public static void setCustomizerDrawableColor(final View target, final int color) {
    final Drawable d = target.getDrawable();
    LayerDrawable layer = (LayerDrawable)d;
    GradientDrawable gradient = (GradientDrawable)layer.getDrawable(0);
    gradient.setColor(color);
    gradient.invalidateSelf();
    layer.invalidateSelf();
    target.invalidate();
    }

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.