我发现现在已经弃用了ProgressDialog.除了ProgressBar之外,还有什么可替代使用它.
我正在使用android studio版本2.3.3.
ProgressDialog progressDialog=new ProgressDialog(this);
progressDialog.show();
解决方法:
是的,在API级别26中,它已被弃用,您可以使用进度条.
使用此代码以编程方式创建:
RelativeLayout layout = findViewById(R.id.display); //specify here Root layout Id
(or)
RelativeLayout layout = findViewById(this);
progressBar = new ProgressBar(youractivity.this,null,android.R.attr.progressBarStyleLarge);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(100,100);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
layout.addView(progressBar,params);
progressBar.setVisibility(View.VISIBLE); //To show ProgressBar
progressBar.setVisibility(View.GONE); // To Hide ProgressBar
要禁用用户交互,您只需添加以下内容即可
码
06001
要恢复用户交互,您只需添加以下代码即可
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
仅供将来参考,将android.R.attr.progressBarStyleSmall更改为android.R.attr.progressBarStyleHorizontal.
This below line code works only above API 21
progressBar.setProgressTintList(ColorStateList.valueOf(Color.RED));
解决方案2:另一种方式
<ProgressBar
android:id="@+id/progressbar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
android:max="100"
android:backgroundTint="@color/white"
android:layout_below="@+id/framelauout"
android:indeterminateTint="#1a09d6"
android:layout_marginTop="-7dp"/>
Activity.java
progressBar = (ProgressBar) findViewById(R.id.progressbar);
`progressBar.setVisibility(View.VISIBLE);`// To Show ProgressBar
`progressBar.setVisibility(View.INVISIBLE);` //To Hide ProgressBar
For more Details: 07001
07002
我希望这可以帮到你.