0

I have developed this solution to show notifications in the actionbar. The result is that

enter image description here

Like can you there is no right margin in the shape and I want something like this

enter image description here

My code is extracted from Actionbar notification count icon (badge) like Google has. And this is my code:

main.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
    android:id="@+id/badge"
    android:actionLayout="@layout/feed_update_count"
    android:icon="@layout/custom_shape_notification"
    android:showAsAction="always">
</item>
</menu>

custom_shape_notifications.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<stroke
    android:width="2dp"
    android:color="#22000000" />

<corners android:radius="5dp" />

<solid android:color="#CC0001" />

feed_update_count.xml

    <?xml version="1.0" encoding="utf-8"?>
    <Button xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/notif_count"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:minWidth="32dp"
          android:minHeight="32dp"
          android:background="@layout/custom_shape_notification"
          android:text="1"
          android:textSize="16sp"
          android:textColor="@android:color/white"
          android:gravity="center"
          android:padding="2dp"
          android:singleLine="true">    
</Button>

Can anyone help me?

Community
  • 1
  • 1
aloj
  • 3,194
  • 7
  • 27
  • 38

2 Answers2

1

Kindly wrap the button in a layout(Linear, Relative etc.) of your choice and add the layout margin to it and it will work.

nikhil.thakkar
  • 1,093
  • 7
  • 12
1

Wrap your button inside relative layout using wrap_content attributes and use android:paddingRight="10dp" in your relative layout file in feed_update_count.xml.

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingRight="15dp"
    android:layout_gravity="end|center_vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:textColor="#ffffff"
            android:paddingLeft="10dp"
            android:textSize="16sp"
            android:paddingRight="10dp"
            android:gravity="center"
            android:text="APPLY"/>

</RelativeLayout>