Elevation is not shown on toolbar in pre-lollipop devices
Asked Answered
S

1

6

I want to show the same elevation effect on my toobar on a KitKat device as seen on a Lollipop device. Below are screenshots for both the KitKat and Lollipop devices. I have referred to this link but my problem is not solved yet.

Lollipop Device:

enter image description here


Kitkat Device:

enter image description here


ContentMain.xml

<android.support.design.widget.CoordinatorLayout 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"
tools:context="com.global.market.checkinternet.MainActivity">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#fff"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />



</android.support.design.widget.AppBarLayout>
    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMode="scrollable"
        android:background="#3F51B5"
        style="@style/MyCustomTabLayout"
        app:tabTextColor="#ffffff"/>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"  />


</LinearLayout>


app_bar_main.xml

    <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:fitsSystemWindows="true"
    tools:context="com.global.market.MainActivity">

    <include layout="@layout/content_main" />



</android.support.design.widget.CoordinatorLayout>
Spirelet answered 20/7, 2016 at 8:58 Comment(1)
Elevation is not available below lollipopRoentgen
A
0

As mentioned, elevation is not available below lollipop devices but, there are few alternative ways for doing that.

I've personally tried everything and none worked but could managed it by adding a layout-v19 folder in res folder of project. So, it will be a specific API-19 layout. There, you can add a view under Toolbar-AppbarLayout (depends on your design) with 4dp height or any other methods as following links:

https://github.com/vipulasri/Toolbar-Elevation-Pre-Lollipop

And this: https://mobikul.com/show-shadow-toolbar-api-21/

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar" />
    </android.support.design.widget.AppBarLayout>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!--  Place Your Layout Here  -->

        <View
            android:id="@+id/shadow_view"
            android:layout_width="match_parent"
            android:layout_height="5dp"
            android:background="@drawable/dropshadow" />

    </FrameLayout>

</LinearLayout>

dropshadow.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <gradient android:startColor="@android:color/transparent"
        android:endColor="#60555555"
        android:angle="90"/>

</shape>

And in java-kotlin side, check if it is API-19, then inflate the layout there:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        v = inflator.inflate(R.layout.item_showdetail_asset_kitkat, this);
    } else {
        v = inflator.inflate(R.layout.item_showdetail_asset, this);
    } 

Hope this helps.

Alonsoalonzo answered 20/8, 2018 at 11:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.