Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change direction of android elevation shadow?

I have FrameLayout with android:elevation="4dp". Shadow of this elevation directed down. I want change direction of shadow to up.

<FrameLayout     android:id="@+id/container"     android:layout_width="match_parent"     android:layout_height="100dp"     android:elevation="10dp"     android:layout_marginBottom="100dp"     android:background="@color/ColorPrimary"     android:layout_alignParentBottom="true"     android:layout_alignParentLeft="true"     android:layout_alignParentStart="true"> </FrameLayout> 
like image 224
Valery Miller Avatar asked Sep 20 '15 09:09

Valery Miller


People also ask

How do I set elevation in Android?

To set the default (resting) elevation of a view, use the android:elevation attribute in the XML layout. To set the elevation of a view in the code of an activity, use the View. setElevation() method. To set the translation of a view, use the View.

Can we change elevation color in Android?

No, the color of the shadow provided by the framework cannot be changed.

How do I change the color of my shadow in Cardview?

You need to use a drawable background ( shadow. xml ) in the parent layout which is looking like a shadow. You can replace FF46A9 in shadow. xml to change the color of shadow.


1 Answers

I consider this method is the best solution: Android Bottom Navigation Bar with drop shadow Thanks, Alexander Bilchuk.

Solution:

You can draw your own shadow just above the view using simple View and its background:

<View     android:layout_width="match_parent"     android:layout_height="4dp"     android:layout_above="@id/bottom_bar"     android:background="@drawable/shadow"/> 

drawable/shadow.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android">     <gradient         android:startColor="#1F000000"         android:endColor="@android:color/transparent"         android:angle="90" /> </shape> 

Also, there are no compatibility issues if use this approach.

like image 184
Valery Miller Avatar answered Sep 29 '22 15:09

Valery Miller