Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am not sure if this is the best solution or not, but it is what I need.</p> <p>Please tell me if you know what is need to be changed for better performance or quality. In my case, I have a button.</p> <p>Custom item on my menu - main.xml</p> <pre><code>&lt;item android:id="@+id/badge" android:actionLayout="@layout/feed_update_count" android:icon="@drawable/shape_notification" android:showAsAction="always"&gt; &lt;/item&gt; </code></pre> <p>Custom shape drawable (background square) - shape_notification.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"&gt; &lt;stroke android:color="#22000000" android:width="2dp"/&gt; &lt;corners android:radius="5dp" /&gt; &lt;solid android:color="#CC0001"/&gt; &lt;/shape&gt; </code></pre> <p>Layout for my view - feed_update_count.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;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="@drawable/shape_notification" android:text="0" android:textSize="16sp" android:textColor="@android:color/white" android:gravity="center" android:padding="2dp" android:singleLine="true"&gt; &lt;/Button&gt; </code></pre> <p>MainActivity - setting and updating my view</p> <pre><code>static Button notifCount; static int mNotifCount = 0; @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getSupportMenuInflater(); inflater.inflate(R.menu.main, menu); View count = menu.findItem(R.id.badge).getActionView(); notifCount = (Button) count.findViewById(R.id.notif_count); notifCount.setText(String.valueOf(mNotifCount)); return super.onCreateOptionsMenu(menu); } private void setNotifCount(int count){ mNotifCount = count; invalidateOptionsMenu(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload