3

I have a button inside my linear layout, and for the linear layout in my activity, even though I am not specifying a background, it appears to be grey in color as shown in the image below. How can I remove that?

enter image description here

Activity Layout file

<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:orientation="vertical">


//This is the linear layout I am talking about where I do not want the grey background
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent"
    android:id="@+id/LinearLayoutView1"
    >

    <Button
        android:id="@+id/uploadAllReportsNew"
        android:layout_width="match_parent"
        android:layout_height="40dp"

        android:background="@drawable/flightclosurebutton"
        android:paddingLeft="30dp"
        android:paddingRight="30dp"
        android:text="Upload All"
        android:layout_gravity="center"
        android:layout_marginRight="15dp"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="15dp"
        android:layout_marginBottom="15dp"


        android:textAllCaps="false"

        />

</LinearLayout>

<com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@+id/bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    app:layout_constraintBottom_toBottomOf="@+id/constraint_layout"
    app:menu="@menu/bottom_navigation" />

</LinearLayout>

enter image description here

Ian Bell
  • 533
  • 5
  • 18
  • If you remove the android:background property on the LinearLayout, or set its value to "@null", what differences are observed? – CSmith Mar 02 '21 at 14:03
  • @CSmith I am unable to set it to '@null' as it does not allow me to. When I remove, it is the same as `android:background="@android:color/transparent"` – Ian Bell Mar 02 '21 at 14:05
  • `android:background="@null"`, not sure what you mean by "it does not allow me to" – CSmith Mar 02 '21 at 14:07
  • Also, what if you delete the inner `LinearLayout` altogether, it doesn't seem to be serving any purpose since only the Button is contained. – CSmith Mar 02 '21 at 14:09
  • Your Linear Layout hasn't defined any color, but it pushes the View upwards, which has a background color. Try to overlap the Linearlayout with the otherone, to achieve the effect you want. – Lukas Mar 02 '21 at 14:09
  • @CSmith it was showing as a red statement that time. I tried again. With `android:background="@null"` also it gives the same output – Ian Bell Mar 02 '21 at 14:09
  • @Lukas I have some fields (TextView, ImageView) in the middle between the two linear layouts , and below all of that I have this other linear layout with the button – Ian Bell Mar 02 '21 at 14:11
  • The @null experiment proves that the gray background is coming from a parent/container view and not the inner `LinearLayout`. You can prove this by forcing a fixed background color (e.g. blue) on the outermost LinearLayout in your hierarchy. – CSmith Mar 02 '21 at 14:18
  • @CSmith Yup that makes sense, so how can I remove it for the inner LinearLayout? – Ian Bell Mar 02 '21 at 14:24
  • `android:background="@null"` effectively means "no background", see https://stackoverflow.com/questions/9311123/is-there-any-diff-null-vs-00000000#:~:text=4%20Answers&text=%40null%20means%20no%20background%20at,has%20a%20fully%2Dtransparent%20color. – CSmith Mar 02 '21 at 14:29
  • @CSmith I added one more image so that it's clearer. I want to remove the grey background completely and just want the activity's background behind the button. – Ian Bell Mar 02 '21 at 14:31
  • you should post all your layout code ... it appears there is a ConstraintLayout somewhere? – CSmith Mar 02 '21 at 14:33
  • Set the background color to #FF0000 to see if this is the actual background you are seeing. – jobbert Mar 02 '21 at 14:37
  • @CSmith I just figured out, needed to add the background to the outermost LinearLayout which is same as my activity's. Thank you so much for your help, really appreciate it :) – Ian Bell Mar 02 '21 at 14:40
  • @jobbert when I add background to the outermost LinearLayout same as my Activity's, it fixes it. Thanks for taking out the time to help :)) – Ian Bell Mar 02 '21 at 14:41
  • You need also set transparent color on the parent LinearLayout or you change the width of your linearlyout to wrap content – Shay Kin Mar 02 '21 at 15:15
  • @ShayKin now the issue is very weird, it shows different outputs on the design within Android Studio and on the emulator – Ian Bell Mar 02 '21 at 15:22
  • 1
    @ShayKin it works now, had to clean the project then rebuild! Thank you for your help :)) – Ian Bell Mar 02 '21 at 16:03
  • Well So it was a problem of the android studio – Shay Kin Mar 02 '21 at 16:14
  • 1
    @ShayKin yup which is pretty strange – Ian Bell Mar 03 '21 at 05:31

0 Answers0