Sam*_*wal 6 xml android shadow android-toolbar android-elevation
我想在Lickipop设备上看到的KitKat设备上我的工具栏上显示相同的高程效果.以下是KitKat和Lollipop设备的屏幕截图.我已经提到了这个链接,但我的问题还没有解决.
棒棒糖装置:
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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
如前所述,在棒棒糖设备下无法使用海拔高度,但是几乎没有其他方法可以做到这一点。
我个人尝试了所有方法,但没有一个有效,但可以通过在项目文件夹layout-v19中添加一个文件夹来管理它。res因此,它将是一个特定的API-19 layout。在那里,您可以添加一个view下Toolbar- AppbarLayout(取决于您的设计)4dp height或任何其他方法,如下链接:
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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
在 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);
}
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助。