【问题标题】:Is it ok to use png as a button background?可以使用png作为按钮背景吗?
【发布时间】:2018-01-30 13:27:34
【问题描述】:

使用png 作为ButtonEditText 的背景有什么缺点吗?或者我应该为 Button 或 EditText 的背景为XML 编写代码。我想知道哪种方法更好。

【问题讨论】:

  • 避免使用 PNG 或 JPG 图片作为背景,直到您可以使用 Shape Drawables 完成 UI 设计。

标签: android android-edittext android-button


【解决方案1】:

您可以使用颜色、可绘制文件或图像作为背景

颜色

android:background="#2F6699"

可绘制

android:background="@drawable/edittext_background"

图片

android:background="@drawable/ic_launcher"

可绘制文件

<?xml version="1.0" encoding="utf-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:thickness="0dp"
       android:shape="rectangle">

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

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

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

【讨论】:

    【解决方案2】:

    我认为您可以尝试 9 补丁 图像作为按钮和编辑文本背景。

    9 补丁:

    9-Patch 图像是可拉伸、可重复的图像,缩小到它们的 最小尺寸;用户画一个右下角,纯黑色1像素 边框告诉系统如何在图像中放置内容。

    有关更多信息,请访问此帖子:

    Utility of android nine patch

    【讨论】:

      【解决方案3】:

      只需将 png 图像放入 drawable 中,然后通过 android:background="@drawable/image.png" 将其设置在 xml 中

      【讨论】:

        【解决方案4】:

        在按钮属性中使用它

        android:background="@drawable/imageName"
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-11-21
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多