android - 如何为形状添加深度

标签 android

我需要让我的 EditText 看起来像下图一样有深度。

我有这个形状我不知道要添加什么

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

    <corners android:radius="50dp" />

    <solid android:color="@color/primary_dark" />

</shape>

enter image description here

最佳答案

你可以用这样的 drawable 来完成:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!--background to compensate the transparency under shadow and glow (for bigger depth values)-->
    <item>
        <shape android:shape="rectangle">
            <corners android:radius="50dp" />
            <solid android:color="@color/primary_dark" />
        </shape>
    </item>

    <!--top, dark, inner shadow-->
    <item
        android:bottom="@dimen/depth">
        <shape android:shape="rectangle">
            <corners android:radius="50dp" />
            <solid android:color="#1A000000" />
        </shape>
    </item>

    <!--bottom, light, outer glow-->
    <item
        android:top="@dimen/depth">
        <shape android:shape="rectangle">
            <corners android:radius="50dp" />
            <solid android:color="#4DFFFFFF" />
        </shape>
    </item>

    <!--your color-->
    <item
        android:top="@dimen/depth"
        android:bottom="@dimen/depth">
        <shape android:shape="rectangle">
            <corners android:radius="50dp" />
            <solid android:color="@color/primary_dark />
        </shape>
    </item>
</layer-list>

并在dimens.xml中定义一个dimen

<dimen name="depth">2dp</dimen>

通过改变dimen你可以改变drawable的深度

关于android - 如何为形状添加深度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28110227/

相关文章:

java - Firebase 数据映射到 Java 类

android - 从 baseadapter 传递项目 id

用于 Android 的基于 Java 的加密库

java - fragment 翻译和电话方向错误

Android加载大位图

android - 如何将另一个 Layout 放在 Scrollview 之上

android - 是否有 API 可以检测操作系统正在使用哪个主题 - 深色或浅色(或其他)?

android - NoSuchMethodError : No virtual method removeOnPageChangeListener 错误

android - 如何为 Android 项目创建新布局(使用 Eclipse)

android - Robolectric 和 Evernotes android-job 库