rajeev kumar
rajeev kumar

Reputation: 249

How to show progress spinner in toolbar

I want to show progress spinner on toolbar while performing background task in UIfragment. I want to use material design for my app, so I set theme with no action bar and used toolbar as action bar. I have tried setProgressBarIndeterminateVisibility(Boolean.TRUE) but its not working.

Upvotes: 3

Views: 3503

Answers (2)

rajeev kumar
rajeev kumar

Reputation: 249

i solved it by just placing the progress bar inside the toolbar in parent activity layout and then from child fragment accessed the progress bar and showed it when needed

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:elevation="3dp"
    android:minHeight="?attr/actionBarSize"
    android:theme="@style/Base.ThemeOverlay.AppCompat.Dark"
    local:popupTheme="@style/ThemeOverlay.AppCompat.Light" >
    <ProgressBar
        android:id="@+id/toolbar_progress_bar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminateTint="#cccccc"
        android:indeterminateTintMode="src_in"
        android:indeterminate="true"
        android:layout_gravity="right"
        android:visibility="gone"
        />
</android.support.v7.widget.Toolbar>

Upvotes: 4

Sasi Kumar
Sasi Kumar

Reputation: 13313

If you extends from a ActionBarActivity, try this:

public class MainActivity extends ActionBarActivity {

boolean showUp=true;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.activity_main);
    setSupportProgressBarIndeterminateVisibility(Boolean.TRUE);

    Button b = (Button) findViewById(R.id.myButton);
    b.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            if(showUp){
                setSupportProgressBarIndeterminateVisibility(Boolean.FALSE);
            }else {
                setSupportProgressBarIndeterminateVisibility(Boolean.TRUE);
            }
            showUp=!showUp;
        }
    });
}

Upvotes: 1

Related Questions