I\'m trying to add a progress bar to my actionBar. I\'m talking about the spinning circle. I did a request and tried to set is vissible, but nothing happens. I have read man
Window provided Progress Bars are now deprecated with Toolbar.
you must use:
setSupportProgressBarIndeterminateVisibility(true);
instead of
setProgressBarIndeterminateVisibility(true);
because you extends ActionBarActivity
. (because you are using supportRequestWindowFeature
instead of requestWindowFeature
)
If it crashes this is a known issue. If your library is updated sorry but it is now just a no-op:
setSupportProgressBarIndeterminateVisibility() crashing has been fixed for a future release, in that it will be a no-op.
My solution:
use toolbar with progressBar widget:
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress_spinner);
progressBar.setVisibility(View.VISIBLE);
}
Layouts:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/toolbar"/>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
and
toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ProgressBar
android:id="@+id/progress_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:indeterminate="true"
android:visibility="gone" />
</android.support.v7.widget.Toolbar>