Border in shape xml

前端 未结 3 1400
逝去的感伤
逝去的感伤 2020-12-12 13:12

I am trying to make a drawable to use for a button. I would like it to have this coloring, with a 2px border around it.

Everything works just fine except I cannot ge

相关标签:
3条回答
  • 2020-12-12 13:55

    It looks like you forgot the prefix on the color attribute. Try

     <stroke android:width="2dp" android:color="#ff00ffff"/>
    
    0 讨论(0)
  • 2020-12-12 14:08

    If you want make a border in a shape xml. You need to use:

    For the external border,you need to use:

    <stroke/>
    

    For the internal background,you need to use:

    <solid/>
    

    If you want to set corners,you need to use:

    <corners/>
    

    If you want a padding betwen border and the internal elements,you need to use:

    <padding/>
    

    Here is a shape xml example using the above items. It works for me

    <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>
    
    0 讨论(0)
  • 2020-12-12 14:09

    We can add drawable .xml like below

    <?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>
    
    0 讨论(0)
提交回复
热议问题