2

I want to set background color to transparent. I've tried with this SameProblem but it doesn't work.

This is the my interface. I need the first ConstraintLayout to be transparent I used "android:background="#00000000" " but no result (background white).

enter image description here

This is my xml file :

<?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"
android:background="#00000000"
tools:context=".AddEditNote">

<android.support.constraint.ConstraintLayout
    android:id="@+id/constraintLayout2"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginStart="6dp"
    android:layout_marginTop="26dp"
    android:layout_marginEnd="6dp"
    android:layout_marginBottom="26dp"
    android:background="@drawable/a"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <EditText
        android:id="@+id/note"
        android:layout_width="343dp"
        android:layout_height="487dp"
        android:layout_marginBottom="44dp"
        android:background="@color/cardview_shadow_start_color"
        android:hint="Note"
        android:inputType="textMultiLine"
        android:textColorHint="@color/aidialog_background"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.509"
        app:layout_constraintStart_toStartOf="parent" />

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="393dp"
        android:layout_height="49dp"
        android:layout_marginTop="4dp"
        android:background="@drawable/circle2"
        android:elevation="4dp"
        android:minHeight="?attr/actionBarSize"
        android:theme="?attr/actionBarTheme"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.6"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

  </android.support.constraint.ConstraintLayout>
  </android.support.constraint.ConstraintLayout>

Thank you.

VIN
  • 6,385
  • 7
  • 38
  • 77
Monir
  • 53
  • 2
  • 9
  • background="@null" to get rid of a background though just getting rid of the background="#000" should work since usually the layouts don't have a background by default – ivan Jun 24 '19 at 22:35
  • Wait, what's behind your constraing layout? are you sure there is something? if not then why do you want it to be transparent? If there is nothing behind its natural that you'd see white – ivan Jun 24 '19 at 22:37
  • I want just to show the second constraints layout (that’s why I need to set first one background color to transparent) – Monir Jun 24 '19 at 23:11

4 Answers4

0

You can try deleting the android:background="#00000000" attribute, or changing it to background="@android:color/transparent".

VIN
  • 6,385
  • 7
  • 38
  • 77
0

We can use LinearLayout as parent of the ConstraintLayout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="#fff">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#000"
        tools:context=".MainActivity">

     ...

    </android.support.constraint.ConstraintLayout>
</LinearLayout>
Wang Liang
  • 4,244
  • 6
  • 22
  • 45
  • This is not a good option to add a wrapper for ConstraintLayout when you can simple add the android:background="null" instead – Edhar Khimich Jun 25 '19 at 02:01
0

Add the attribute to your XML: android:background="@android:color/transparent" or android:background="null"

This will remove your background color and make it transparent.

If you want to read move about ConstraintLayout - https://developer.android.com/training/constraint-layout

Edhar Khimich
  • 1,468
  • 1
  • 17
  • 20
  • 1
    still don't wrok – Monir Jun 25 '19 at 10:01
  • 1
    you cannot add "null", because there is no "null" attribute in the android:background – Cyd Jul 13 '20 at 12:20
  • @Cyd Yes, you can null means no background at all (View.getBackground() returns null). #00000000 means that you got a ColorDrawable as the background which has a fully-transparent color. If you don't want to have a background make it null it should perform better. To use null from the code you can try doing: – Edhar Khimich Jul 13 '20 at 12:38
  • @EdgarKhimich :( it's not working for me. i've been doing all the suggestions here for 3 hours now and still not working for BottomSheetDialogFragment. – Cyd Jul 13 '20 at 13:13
0

You need to change the alpha in the color code to increase or decrease the amount of Transparency :

1.You can range it from 00 to FF (Hex Decimal)

2.For maximum transparency => #ff______ (Here ff stands for the alpha)

3.For minimum or no transparency => #00______ (Here 00 stands for the alpha)

so simply add android: background="#00000000" to your constraint layout