【问题标题】:Border in shape XML形状 XML 中的边框
【发布时间】:2021-04-02 03:52:14
【问题描述】:

我正在尝试制作用于按钮的可绘制对象。我希望它有这种颜色,周围有 2px 的边框。

一切都很好,只是我无法显示边框......

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

    <gradient android:startColor="@color/bar_clicked_dark"
        android:endColor="@color/bar_clicked_light"
        android:angle="90"/>

    <corners android:bottomLeftRadius="0dp"
        android:topLeftRadius="15dp"
        android:bottomRightRadius="15dp"
        android:topRightRadius="0dp" />

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

</shape>

【问题讨论】:

    标签: android android-layout border shapes stroke


    【解决方案1】:

    您似乎忘记了颜色属性的前缀。试试看

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

    【讨论】:

      【解决方案2】:

      如果您想在形状 xml 中制作边框。你需要使用:

      对于外部边框,你需要使用:

      <stroke/>
      

      对于内部背景,你需要使用:

      <solid/>
      

      如果要设置角点,需要使用:

      <corners/>
      

      如果你想在边框和内部元素之间有一个填充,你需要使用:

      <padding/>
      

      这是一个使用上述项目的 shape xml 示例。它对我有用

      <shape xmlns:android="http://schemas.android.com/apk/res/android"> 
        <stroke android:width="2dp" android:color="#D0CFCC" /> 
        <solid android:color="#F8F7F5" /> 
        <corners android:radius="10dp" />
        <padding android:left="2dp" android:top="2dp" android:right="2dp" android:bottom="2dp" />
      </shape>
      

      【讨论】:

      • 以及如何使用这种类型的 xml drawable 制作“U”形?
      【解决方案3】:

      我们可以像下面这样添加drawable .xml

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-13
        • 2014-03-13
        • 2015-06-12
        • 2016-05-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多