android - 如何删除我的布局背景以便我可以看到它背后的活动?
问题描述
我正在实现一个自定义加载屏幕,ProgressBar
并TextView
显示我正在加载活动的数据。目前,包含ProgressBar
并TextView
显示灰色背景的布局,我想将其删除。我只想显示没有任何背景的加载文本和进度条。我怎样才能做到这一点?
布局文件
<androidx.constraintlayout.widget.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"
>
<ProgressBar
android:id="@+id/progressBarloading"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading..."
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/progressBarloading"
app:layout_constraintVertical_bias="0.074"
android:textSize="18sp"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
目前它看起来像这样,我怎样才能去除灰色背景?
解决方案
嗨,如果你想制作透明对话框,你必须在你的布局和你需要使用的对话框中将背景更改为透明 dialog.getWindow().getDecorView().setBackgroundColor(Color.TRANSPARENT);
这是我的代码
布局.xml:
<androidx.constraintlayout.widget.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"
android:background="@android:color/transparent"
>
<ProgressBar
android:id="@+id/progressBarloading"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading..."
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/progressBarloading"
app:layout_constraintVertical_bias="0.074" />
</androidx.constraintlayout.widget.ConstraintLayout>
这是对话框中的代码:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
View view = LayoutInflater.from(this).inflate(R.layout.dialog, null, false);
builder.setView(view);
AlertDialog dialog = builder.create();
dialog.show();
dialog.getWindow().getDecorView().setBackgroundColor(Color.TRANSPARENT);
推荐阅读
- python - 避免for循环?
- spring-boot - 在父抽象类中使用 HATEOAS RepresentationModel
- batch-file - Windows Batch:CMD 完成后调用
- python - 使用 Python 将文件移入和移出 Amazon S3 存储桶键
- sql - ORA-22992 / ORA-06502+ORA-06512 错误
- android - Android:使用 jetpack 导航,如何在不破坏后退按钮的情况下向片段添加折叠工具栏布局?
- plsql - Oracle 12c:以日期间隔运行计划作业
- java - Java:尽管有异常处理,线程仍会停止
- c - 打印列表时省略最后一个逗号
- java - Intellij IDEA 2019.2.4 似乎无法识别 JDK 12 中的 javafx 包