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 many likely questions but is still couldn't figure out what i'm doing wrong.
My code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);//Above setContentView, very important
setContentView(R.layout.activity_main);
//...other stuff
}
In an other method which i don't call in on create.(It's an onClick method)
public void plus(View view){
setProgressBarIndeterminateVisibility(true);//Nothing happens
//...other stuff
}
I do not understand what's wrong, please help me.
NOTE: I never set it to false
Edit: I tried mmlooloo second part, but absolutly noting happend. Not even part 3. So I tried part 4, but i gave me an exception.
"This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead."
I removed the Window.FEATURE_ACTION_BAR request, but it gave me the same exception. I don't think i need to set windowActionBar to false, but I did and it still gave me the same exception.
Any other options?
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With