Changing view on Menu Item in Action Bar

混江龙づ霸主 提交于 2019-12-01 04:46:29

Instead of setting your action view class to a ProgressBar, set it to a custom LinearLayout class, as such:

class MyViewItem extends LinearLayout

Add a ProgressBar and an ImageView as children in its constructor with addView, and set these childrens' visibilities as either GONE or VISIBLE when your code requires it.

Try to use:

<item
    android:id="@+id/main_menu_refresh"
    android:enabled="true"
    android:icon="@drawable/refresh"
    android:orderInCategory="1"
    android:title="@string/refresh"
    app:showAsAction="ifRoom"
    app:actionViewClass="android.widget.ProgressBar">
</item>

Note this two lines:

    app:showAsAction="ifRoom"
    app:actionViewClass="android.widget.ProgressBar"

Did you try to fetch your menu item like this?

MenuItem item = getToolbar().getMenu().findItem(Menu.FIRST);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!