Is there a simpler/better way to put a border/outline around my TextView?

前端 未结 2 1047
[愿得一人]
[愿得一人] 2021-02-03 23:05

So I wanted to have a TextView with a cool border around it. I couldn\'t find any standard way of doing it, so I came up with this:

@drawable/custom_bg_1: A blue rounded

相关标签:
2条回答
  • 2021-02-03 23:33

    You can probably get by with just custom_bg_2 if you add a <stroke> section:

    <?xml version="1.0" encoding="UTF-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <solid android:color="#FFFFFF"/>
        <corners android:radius="3dp" />
        <padding android:left="10dp" android:top="10dp"
            android:right="10dp" android:bottom="10dp" />
        <stroke android:color="#439CC8" android:width="2dp" />
    </shape>
    
    0 讨论(0)
  • 2021-02-03 23:35

    Why not try stroke instead of solid?

    According to Shape Drawable you can do something like:

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

    instead of <solid/> and then set it as your TextView background.

    0 讨论(0)
提交回复
热议问题