2014-01-28 4 views
0

Я разработал это решение, чтобы показывать уведомления в панели действий. Результатом является то, чтоПоля значков панели действий

enter image description here

Как вы можете не правый край в форме, и я хочу что-то вроде этого

enter image description here

Мой код извлекается из Actionbar notification count icon (badge) like Google has. И это мой код:

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> 

Может кто-нибудь мне помочь?

ответ

1

Просьба обмануть кнопку в макете (линейный, относительный и т. Д.) По вашему выбору и добавить к ней макет макета, и он будет работать.

1

Оберните свою кнопку внутри относительной компоновки с использованием атрибутов wrap_content и используйте android: paddingRight = "10dp" в вашем файле относительной компоновки в файле 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> 
Смежные вопросы