android - 进度对话框未显示 android 8.0 版中的微调器,但它仍然有效
问题描述
在我的应用程序中,单击按钮时应显示进度对话框。现在显示进度对话框,但没有微调器或加载栏(抱歉,我不确定它叫什么)
这就是我的进度对话框在 android 8.0 真实设备中的样子
这就是我的进度对话框在 android 5.0 中的样子
private ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
progressDialog = new ProgressDialog(Login.this);
}
public void loginUser(View v) {
final String Email = emailText.getText().toString();
final String password = passwordText.getText().toString();
progressDialog.setMessage("Logging in....");
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();
if (TextUtils.isEmpty(Email)) {
emailText.setError("Email is required");
}
if (TextUtils.isEmpty(password)) {
passwordText.setError("password is required");
}
if ((!TextUtils.isEmpty(Email)) && (!TextUtils.isEmpty(password))) {
mAuth.signInWithEmailAndPassword(Email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (!task.isSuccessful()) {
Toasty.error(getApplicationContext(), "Login Failed",
Toast.LENGTH_SHORT, true).show();
progressDialog.dismiss();
} else {
Toasty.success(getApplicationContext(), "Login Success",
Toast.LENGTH_SHORT, true).show();
Intent intent = new Intent(Login.this, Admins.class);
intent.putExtra("Email", emailText.getText().toString());
startActivity(intent);
}
}
}
谁能帮我解决这个问题?
解决方案
进度对话框
已从 SDK 26 中弃用。您应该使用
进度条
用法:
在您的布局中添加视图:
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="@+id/parent"
app:layout_constraintBottom_toBottomOf="@+id/parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:indeterminate="true"
android:max="100"
android:visibility="gone"/>
progressBar
在你的活动中声明你
ProgressBar progressBar;
在onCreate
获取视图
progressBar = findViewById(R.id.progressBar);
当你需要显示progressBar时:
progressBar.setVisibility(View.VISIBLE);
当你需要它消失时:
progressBar.setVisibility(View.GONE);
有关更多详细信息,请查看ProgressBar文档
在启动时禁用用户交互可能会有所帮助ProgressBar
。
编辑
禁用交互
getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
重新启用交互:
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
编辑 2
您不需要ProgressDialog
按照 Material Design 模式(进度指示器)复制视觉效果。
编辑 3
这是我在评论中对你说的话的一个例子。它是 View 内 ProgressBar 的布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_margin="16dp"
android:visibility="visible"
android:background="#EFEFEF">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Things to do"
android:textSize="30sp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"/>
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:indeterminate="true"
android:max="100"
android:visibility="visible"
android:layout_below="@+id/title"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Please wait we are doing things..."
android:layout_below="@+id/title"
android:layout_toRightOf="@+id/progressBar"
android:layout_toEndOf="@+id/progressBar"/>
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
您可以为 API 21 或更高版本设置提升:
android:elevation="10dp"
正如您在评论中所问的那样,这只是一个示例,而不是建议。这不是你在生活中看到的最美丽的布局,但它会给你一个北方。
推荐阅读
- scala - 在 Scala 中使用 For Comprehension 在 If 测试后仅使用 flatMap Future[T]
- c# - 使用实体框架从多对多关系中选择数据
- mocha.js - mocha chai 如何根据条件添加自定义标题
- php - 为什么 .env 文件中的值是空的?
- python - 我可以向新创建的用户的辅助电子邮件发送新帐户通知吗?
- android - LeakCanary 构建失败,构建类型不是调试或发布
- audio - 如何使用 VLC 命令行转换和规范化音频?
- javascript - 在 extjs 6 中编辑后重新加载商店和网格
- google-apps-script - 获取数组的第一列
- android - Android studio 3.1.4 意外结束 ZLIB 输入流错误