gpt4 book ai didi

android - 我怎样才能建立这样的按钮?

转载 作者:行者123 更新时间:2023-11-30 04:19:07 25 4
gpt4 key购买 nike

我需要为我的 Android 应用实现这样的按钮。如果不使用完整图像作为按钮就可以做到这一点。
我使用 <shape> 完成了几乎相同的按钮与 <gradient> .我唯一需要的是添加底部蓝色按钮阴影并包含图像。

Button

这可能吗?

提前致谢。

最佳答案

您可以通过在 Layered Drawable 中组合 Shape Drawable 来做到这一点。为此,您将拥有 3 个 xml 文件,如下所示:

  • button.xml(我猜你已经有了)

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

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

    <gradient
    android:angle="270"
    android:centerColor="#FFFFFF"
    android:endColor="#CAEBF8"
    android:startColor="#FFFFFF"
    android:type="linear" />

    <padding
    android:bottom="8dp"
    android:left="8dp"
    android:right="8dp"
    android:top="8dp" />

    <stroke
    android:width="2dp"
    android:color="#FFFFFF" />

    </shape>
  • button_bg.xml(在按钮下方添加蓝色边框)

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

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

    <solid android:color="#6FC8F1" />

    </shape>
  • layered_button.xml(合并之前的 xml 和用作按钮背景的可绘制对象)

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:drawable="@drawable/button_bg"/>
    <item
    android:bottom="2dp"
    android:drawable="@drawable/button"/>

    </layer-list>

您将在 Drawables Documentation 中找到有关图层列表的更多信息

关于android - 我怎样才能建立这样的按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9531198/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com