2

i just try to add shadow to my LinearLayout to make my View act like its over other view just like this image facebook messenger

image

i try this xml as background from my View but its seems like a line not shadow

<shape android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:startColor="@color/black_alpha_12" 
android:endColor="@android:color/transparent" android:angle="90.0" />
</shape>

and i try many xml code in stackoverflow no one help me to make shadow like what i want

Ratilal Chopda
  • 4,162
  • 4
  • 18
  • 31
Medo Zeus
  • 99
  • 2
  • 9

6 Answers6

3

Use

getSupportActionBar().setElevation(10);

But as per Your Above Comment in my app i made an LinearLayout as ActionBar did this will work

Than Use

YourView.setElevation(10);
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
1

Try this

getSupportActionBar().setElevation(10);
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Ratilal Chopda
  • 4,162
  • 4
  • 18
  • 31
0

Try this

getSupportActionBar().setElevation(10);

Another reference i had answered here first Example

Hope this may helps you

InsaneCat
  • 2,115
  • 5
  • 21
  • 40
0

HI for shadow effect you can you cardview or view.setElevation(10); both will work.

ref-How to add shadow on CardView aligned to bottom of parent

ref-https://material.io/guidelines/material-design/elevation-shadows.html#

user3876059
  • 90
  • 1
  • 7
0

Attribute elevation is only used in API level 21 and higher For example, some tags can be unused too, such as the new element in layouts introduced in API 21.

Set the elevation property in xml to say 10dp or 8dp android:elevation="10dp"

Abraham Mathew
  • 2,029
  • 3
  • 21
  • 42
-1

Use <layer-list> for set background of view. Like this

<TextView
  android:id="@+id/tv_item"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:background="@drawable/keyboard_btn_bg"
    />

keyboard_btn_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <size
                android:width="130dp"
                android:height="25dp" />
            <corners android:radius="8dp" />

            <padding
                android:bottom="2dp"/>
            <stroke
                android:width="0dp"
                android:color="#20000000" />
            <solid android:color="#20000000" />
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle">
            <size
                android:width="160dp"
                android:height="25dp" />
            <corners android:radius="8dp" />
            <padding
                android:top="8dp"
                android:bottom="8dp"
                android:left="8dp"
                android:right="8dp"
                />
            <stroke
                android:width="1dp"
                android:color="#808080" />
            <solid android:color="#ffffff" />
        </shape>
    </item>
Rajpal
  • 57
  • 5