Question

Hello I am having action bar which I made using appcompat library in android. It looks like

enter image description here

When I click on the refresh menu item then I here show the progress bar and it is displaying perfectly

menuItem.setActionView(R.layout.progressbar);
menuItem.expandActionView();

enter image description here

progressbar.xml

<?xml version="1.0" encoding="utf-8"?>
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

</ProgressBar> 

but after my task done in async task I am doing to stop it in onPostExecute like below which is not working, means progress bar still executing after that also. I want to hide it and show refresh button after this process complete but it is not working currently

menuItem.collapseActionView();
menuItem.setActionView(null);

Any idea what it is wrong ?

Was it helpful?

Solution

I can guess, you've forgot to invalidate action bar. If you, then just call invalidateOptionsMenu() . And see the magic ;)

menuItem.collapseActionView();
menuItem.setActionView(null);
YourActivity.this.invalidateOptionsMenu();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top