0

I am implementing a custom loading screen with a ProgressBar and TextView to show the user that I am loading the data on the activity. Currently, the layout comprising of ProgressBar and TextView shows a greyish background, and I want to remove it. I just want to show the loading text and progress bar without any background. How can I achieve that?

Layout file

<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>

Currently it looks like this, how can I remove the greyish background?

enter image description here

Shay Kin
  • 2,539
  • 3
  • 15
  • 22
Ian Bell
  • 533
  • 5
  • 18

1 Answers1

1

Hi if you want to make transparent Dialog you must change the background to transparent in your layout and also in your dialog you need to use dialog.getWindow().getDecorView().setBackgroundColor(Color.TRANSPARENT);

and this is my code

Layout.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>

and this the code in the dialog :

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);
Shay Kin
  • 2,539
  • 3
  • 15
  • 22
  • How can I do this with a LinearLayout as well? Like I have a linear layout behind my button, and I want the background behind the button to be transparent. However, when I specify background for my button, it doesn't show the button's background as well – Ian Bell Mar 02 '21 at 15:03
  • In the same layout inside your dialog? – Shay Kin Mar 02 '21 at 15:06
  • 1
    No this has nothing with the dialog. I have posted the question here - https://stackoverflow.com/questions/66440517/how-can-i-remove-the-background-of-linear-layout/66441323#66441323 – Ian Bell Mar 02 '21 at 15:08