Adding Shadow Below TabBar - Material Design
I have an action bar and a tab bar. I removed the shadow under the action bar with
<item name="android:windowContentOverlay">@null</item>
Although, I want to add a shadow below the tab bar. I am using SlidingTabLayout. My TextView tab:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabText"
android:layout_width="wrap_content"
android:layout_height="@dimen/actionbar_height"
android:textColor="@color/tab_color"
android:gravity="center"
android:textAllCaps="true"
android:singleLine="true" />
How to do it?
source to share
jmols is responsible for results in a different shadow than what Google apps use (like Play Newsstand). This is my method that makes the shadow look exactly like Play Newsstand:
Create a callback shadow.xml
:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="@android:color/transparent"
android:endColor="#33000000"
android:angle="90">
</gradient>
</shape>
Then set that shadow to your content layout like:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Your views here -->
<View
android:layout_width="match_parent"
android:layout_height="8dp"
android:background="@drawable/shadow" />
</RelativeLayout>
Placed below the toolbar / action bar, this will look exactly the same as the implementation in Play Newsstand and Play Store.
source to share
Shadows are currently only supported on Api 21 (since they are rendered in real time) and unfortunately not provided by the support library.
Hence, you will have to simulate the shadows yourself using the custom drawing capability at api levels <21. The easiest way to do this is:
- grab the shadow 9 patch from google IO app.
-
set this shadow to your main content layout like:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <Toolbar android:id="@+id/tb_toolbar" android:layout_width="match_parent" android:layout_height="@dimen/abc_action_bar_default_height_material" android:title="@string/toolbar_title" android:elevation="@dimen/toolbar_elevation"/> <FrameLayout android:id="@+id/fl_fragment_container" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@id/tb_toolbar" android:foreground="@drawable/bottom_shadow"/> </RelativeLayout>
Note. The only notable exception to this is CardView, which makes its own shadow in older api levels.
Check out this post for more information.
source to share
If you are using Android Material Design, to add a drop shadow to a view, you need to specify an attribute android:elevation
in your layout or call a method myView.setElevation()
in your code. You can define more definition of shadows with material design in android documentation
source to share