在安卓5.0以下的设备中,工具栏上没有显示“高程”选项。

6

我希望在KitKat设备上展示与Lollipop设备相同的工具栏高程效果。下面是KitKat和Lollipop设备的截图。我已经参考了this链接,但我的问题尚未解决。

Lollipop设备:

enter image description here


Kitkat设备:

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>

3
Lollipop以下的版本不支持高程。 - Riyaz Ahamed
1个回答

0

如前所述,在棒棒糖以下的设备上不支持高度值,但是有一些替代方法。

我个人尝试了所有方法都无效,但是通过在项目的res文件夹中添加一个 layout-v19文件夹来实现。因此,它将是一个特定的 API-19 layout。在那里,您可以根据设计,在Toolbar - AppbarLayout下添加一个 view ,高度为4dp 或任何其他方法,如下面的链接所示:

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

希望这能有所帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接