【问题标题】:Add shadow and depth to a android toolbar向 android 工具栏添加阴影和深度
【发布时间】:2017-01-04 14:32:23
【问题描述】:

我正在尝试在 Xamarin Android 中创建音乐播放器。我在布局底部有一个工具栏,我正在尝试添加一个漂亮的阴影和深度,如下图所示:

这是我的布局:

`<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:minWidth="25px"
    android:minHeight="25px">
    <android.support.v7.widget.Toolbar
        android:id="@+id/IDFIRSTTOOLBAR"
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="0.5"
        android:background="#543011"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
    <android.support.v4.view.ViewPager
        android:id="@+id/IDVIEWPAGER"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3"
        android:background="#ffffff">
        <android.support.v4.view.PagerTabStrip
            android:id="@+id/IDPAGERTABSTRIP"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
            android:paddingBottom="10dp"
            android:paddingTop="10dp"
            android:textColor="#ffffff" />
    </android.support.v4.view.ViewPager>
    <android.support.v7.widget.Toolbar
        android:id="@+id/IDSECONDTOOLBAR"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5"
        android:color="#000000"
        android:background="#e2e2e2" />
</LinearLayout>`

【问题讨论】:

  • 你试过什么?那是MCVE 吗?您的具体问题是什么?
  • 我尝试了 Android Lolipop 中引入的海拔属性,但它不起作用,除此之外,我的项目适用于运行低于 Lolipop 的 android 版本的设备。我也尝试过创建自己的样式,但无法达到我想要的效果。

标签: android xamarin.android shadow


【解决方案1】:

我尝试了 Android Lolipop 中引入的海拔属性,但它不起作用,除此之外,我的项目适用于运行低于 Lolipop 的 android 版本的设备。

由于高程属性不可用,您可以尝试使用shape 创建阴影样式,并使用Toolbarandroid:background 属性应用此样式。

关于shape在xamarin android项目中的使用,可以参考这篇博客:Android Tricks: Using Shape for Theming

或者你也可以尝试使用Layer List来创建你的后台资源。

我已经测试过定义这样的形状:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
  <gradient
     android:angle="90"
     android:endColor="#88444444" />
</shape>

并将其应用到一个按钮中,它适用于 android 4.4 模拟器。

【讨论】:

    猜你喜欢
    • 2018-01-03
    • 2023-04-01
    • 1970-01-01
    • 2016-04-30
    • 2019-12-27
    • 2017-10-05
    • 2016-10-27
    • 2017-07-13
    • 1970-01-01
    相关资源
    最近更新 更多