第一:
Window provided Progress Bars are now deprecated with Toolbar.
第二:
你必须使用:
setSupportProgressBarIndeterminateVisibility(true);
代替
setProgressBarIndeterminateVisibility(true);
因为你扩展了ActionBarActivity. (因为你使用的是SupportRequestWindowFeature而不是requestWindowFeature)
第三:
如果它崩溃了这是一个已知的issue.
如果您的图书馆更新了对不起,但现在只是一个无效的:
setSupportProgressBarIndeterminateVisibility() crashing has been fixed
for a future release, in that it will be a no-op.
第四:
我的解决方案
使用工具栏与progressBar小部件:
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中
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
和
toolbar.xml
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
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" />