【问题标题】:Elevation is not shown on toolbar in pre-lollipop devices棒棒糖前设备的工具栏上未显示高程
【发布时间】:2016-11-23 10:10:02
【问题描述】:

我想在 KitKat 设备上的工具栏上显示与在 Lollipop 设备上相同的高度效果。下面是 KitKat 和 Lollipop 设备的屏幕截图。我已经提到了this链接,但我的问题还没有解决。

棒棒糖设备:


Kitkat 设备:


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>

【问题讨论】:

  • 棒棒糖下方没有标高

标签: android xml android-toolbar shadow android-elevation


【解决方案1】:

如前所述,在棒棒糖设备下方不提供高程,但是几乎没有其他方法可以做到这一点。

我亲自尝试了所有方法,但都没有成功,但可以通过在项目的 res 文件夹中添加 layout-v19 文件夹来管理它。因此,它将是一个特定的 API-19 layout。在那里,您可以使用4dp height 或任何其他方法在Toolbar-AppbarLayout 下添加view(取决于您的设计),如下链接:

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

还有这个: 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>

在 java-kotlin 端,检查是否为API-19,然后在此处扩充布局:

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);
    } 

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-15
    • 1970-01-01
    • 1970-01-01
    • 2015-06-27
    • 2016-05-02
    • 1970-01-01
    • 2016-08-14
    • 2016-02-11
    相关资源
    最近更新 更多