setProgressBarIndeterminateVisibility(真)不工作 [英] setProgressBarIndeterminateVisibility(true) not working
问题描述
我想一个进度条添加到我的动作条。我说的是旋转圈。我做了一个请求,并试图建立是vissible,但没有任何反应。 我看过很多可能的问题,但仍无法弄清楚什么我做错了。
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.
我的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
}
在另一种方法,我不叫上创建。(这是一个onClick方法)
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.
注:我从来没有将其设置为false
NOTE: I never set it to false
编辑: 我试图mmlooloo第二部分,而且是绝对指出happend。即使不是第3部分。所以,我想第4部分,但我给了我一个例外。
I tried mmlooloo second part, but absolutly noting happend. Not even part 3. So I tried part 4, but i gave me an exception.
这个活动已经有靠窗户的装饰提供一个操作栏。 不要求Window.FEATURE_ACTION_BAR并设置windowActionBar为 假在主题用一个工具栏,而不是。
"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."
我删除了Window.FEATURE_ACTION_BAR请求,但它给了我同样的异常。 我不认为我需要设置windowActionBar为假,但我没有,它仍然给了我同样的例外。
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.
任何其他的选择吗?
推荐答案
设置窗口进度条pcated与工具栏现在去$ P $。
First:
您必须使用:
Second:
you must use:
而不是
setProgressBarIndeterminateVisibility(true);
因为你伸出 ActionBarActivity
。 (因为你使用 supportRequestWindowFeature
而不是 requestWindowFeature
)
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()崩溃已得到修复 在以后的版本中,这将是一个空操作。
setSupportProgressBarIndeterminateVisibility() crashing has been fixed for a future release, in that it will be a no-op.
我的解决办法:
使用工具栏进度部件:
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);
}
布局:
activity_main.xml
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>
和
toolbar.xml
toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
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="right"
android:indeterminate="true"
android:visibility="gone" />
</android.support.v7.widget.Toolbar>
这篇关于setProgressBarIndeterminateVisibility(真)不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!