5

Here is my coding. Here is design blue color for TextView's 4 border. What I want is to design only for 3 borders (top, left and bottom).

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" >
        <shape>
            <solid
                android:color="#449def" />
            <stroke
                android:width="1dp"
                android:color="#2f6699" />
            <corners
                android:radius="0dp" />
            <padding
                android:left="5dp"
                android:top="5dp"
                android:right="5dp"
                android:bottom="5dp" />
        </shape>
    </item>
    <item>
        <shape>
            <gradient
                android:startColor="#ffffff"
                android:endColor="#ffffff"
                android:angle="270" />
            <stroke
                android:width="1dp"
                android:color="#2f6699" />
            <corners
                android:radius="0dp" />
            <padding
                android:left="5dp"
                android:top="5dp"
                android:right="5dp"
                android:bottom="5dp" />
        </shape>
    </item>
</selector>
PPShein
  • 13,309
  • 42
  • 142
  • 227
  • http://stackoverflow.com/questions/5254562/is-there-a-simpler-better-way-to-put-a-border-outline-around-my-textview – RobinHood Dec 11 '12 at 05:38

3 Answers3

10

Below code placed at the bottom of height of 1dp, you have to play with this for other sides

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<!-- This is the line -->
<item>
  <shape>
        <solid android:color="#535353" />
  </shape>
</item>

<!-- This is the main color -->
<item android:bottom="1dp">
 <shape>
       <solid android:color="#252525" />
 </shape>
</item>
</layer-list>

Refer this discussion Open-sided Android stroke?

Community
  • 1
  • 1
kumar_android
  • 2,273
  • 1
  • 21
  • 30
2

This is a quick solution (probably dumb), add android:translationX="2dp" on your TextView and you can add android:paddingRight="2dp" to make up for lost space.

Lawrence Gimenez
  • 2,662
  • 4
  • 34
  • 52
1

Try like this

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <padding android:bottom="1dp" android:left="1dp" android:right="0dp"
                android:top="1dp"/>
            <solid android:color="#000"/>
        </shape>
    </item>

    <!-- Background -->
    <item>
        <shape>
            <solid android:color="@color/white"/>

        </shape>
    </item>
</layer-list>
ashkufaraz
  • 5,179
  • 6
  • 51
  • 82