androidandroid-linearlayout

How to disable shadows in LinearLayout in Android Studio


I have an activity which has a constraintLayout at the top and a FrameLayout that wraps a LinearLayout in itself.

How exactly can I disable the shadows that the LinearLayout has at the top and bottom of itself, for a better user experience?

I tried setting android:elevation="0dp" inside my LinearLayout, but nothing changed. What am I doing wrong?

Current code:

<?xml version="1.0" encoding="utf-8"?>
<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="@color/golden_brown"
    tools:context=".MenuActivity">

    <FrameLayout
        android:id="@+id/frameLayout"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@color/white"
        app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">
        <LinearLayout
            android:id="@+id/navigation_drawer_profile"
            android:layout_width="200dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:background="@color/white"
            android:orientation="vertical"
            android:visibility="visible" />
    </FrameLayout>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottomNavigationView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/bottom_navbar_fade"
        app:itemActiveIndicatorStyle="@null"
        app:itemRippleColor="@null"
        app:itemHorizontalTranslationEnabled="false"
        app:itemIconTint="@color/icon_color_selector"
        app:itemTextColor="@color/icon_color_selector"
        app:itemTextAppearanceActive="@style/BottomNavigationViewTextStyleActive"
        app:itemTextAppearanceInactive="@style/BottomNavigationViewTextStyleInactive"
        app:itemIconSize="40dp"
        app:labelVisibilityMode="labeled"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/bottom_nav_menu" />

</androidx.constraintlayout.widget.ConstraintLayout>

Solution

  • To my knowledge, a simple LinearLayout should not have shadows.
    Please check whether the shadow actually appears in the emulator or a real device, and not only in the XML Editor in Android Studio. The XML Editor sometimes shows shadows around the element that the cursor currently stands above.
    There also is a stackoverflow answer that suggests the shadow appears to indicate which orientation is set to the LinearLayout.