【问题标题】:How to add border to button in android [duplicate]如何在android中为按钮添加边框[重复]
【发布时间】:2014-07-01 13:15:33
【问题描述】:

您好,我在按钮中覆盖了我的 ImageView,但是当它们彼此如此接近时,您无法辨认出它是按钮,它只是一个大的红色方块。我需要一种快速简便的方法来给我的按钮边框/边缘或其他东西,以便您可以看到不同的按钮。

【问题讨论】:

    标签: android button imageview


    【解决方案1】:

    在可绘制资源中创建形状

    <shape xmlns:android="http://schemas.android.com/apk/res/android" >
       <solid android:color="#C0213A" />`<!--Background Color-->`
       <stroke android:width="2dip" android:color="#C0213A"/> `<!--Border-->`
    </shape>
    

    在您的 XML 中

    <Button
    android:id="@+id/button"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="15dp"
    android:background="@drawable/your_shape"> `<!--This is your shape created--`>
    

    【讨论】:

      【解决方案2】:

      按钮没有边框,但您可以使用 shape 制作带边框的可绘制对象,然后将其作为按钮的背景。

      <?xml version="1.0" encoding="utf-8"?>
      <shape xmlns:android="http://schemas.android.com/apk/res/android"
          android:shape="rectangle" >
      
          <solid android:color="@color/red" />
      
          <stroke
              android:width="1dp"
              android:color="@color/black" />
      
      </shape>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-02-28
        • 2019-02-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-03-11
        • 1970-01-01
        相关资源
        最近更新 更多