Menu Icon not displaying.
Closed this issue · 11 comments
Here is my menu_item.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:id="@+id/action_notification"
android:orderInCategory="300"
android:title="User"
app:actionLayout="@layout/menu_action_item_badge"
android:icon="@drawable/ic_notifications_black_24dp"
app:showAsAction="always">
</item>
</menu>
Inside MainActivity.java
MenuItem item= menu.findItem(R.id.action_notification);
ActionItemBadge.update(item,1);
I am calling this inside this segment:
private BroadcastReceiver fcmReciever = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
//Badger badge= Badger.getInstance();
Toast.makeText(context,menu.findItem(R.id.action_notification).getTitle().toString(),Toast.LENGTH_LONG).show();
//menu.findItem(R.id.action_notification).setIcon(R.drawable.camera);
MenuItem item= menu.findItem(R.id.action_notification);
ActionItemBadge.update(item,1);
//MainActivity.this.onCreateOptionsMenu(menu);
//new ActionItemBadgeAdder().act(((Activity) context)).menu(menu).
//Toast.makeText(context,"recieved",Toast.LENGTH_LONG).show();
}
};
Is the broadcast receiver happening on the main thread?
I have registered the reciever inside the OnCreate
.
ensure the onReceive happens on the main thread.
Also compare your code with the sample app in which it works.
Perhaps it also breaks with the new androidX or material library
How to ensure that?
This is the project's design and appcompat ver:
implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support:design:27.1.0'
please use google. that's one of the standard things on android :)
ok these dependencies should be fine. just compare how it works in the sample app
https://stackoverflow.com/a/20248093/5192105 according to this it works on the main thread.
I suppose your sample app does not have use of the method:
ActionItemBadge.update(item,1);
Where is the sample app???
Yes I had seen it already. The issue is in menu_item.xml
file.
Because the icon is not displaying even if I don't set the count in the java
file.
So it is not a problem of the library, but the main menu you defined? Make sure you supply a proper available icon