Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create borders on a android view in drawable xml, on 3 sides?

I want to make a drawable for my Android button, defined as drawable. I found I could set all the borders by using a rectangle, but I got kinda stuck when I wanted it on three sides. I want for example have either the top or the bottom open.

Could anyone show me how to do this?

like image 945
user717572 Avatar asked Apr 14 '12 00:04

user717572


People also ask

How do you put a border on android?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code we have taken one text view with background as border so we need to create a file in drawable as boarder.

What is stroke in android XML?

Sometimes you want an outline around your shape and to do that you can use the stroke tag. You can specify the width and color of the outline using android:width and android:color.


1 Answers

Try doing this, though I saw it on some other post

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

<item>
<shape android:shape="rectangle" >
    <solid android:color="#FFFFFF" />
    <padding
        //android:bottom="10dp"  Remove this to avoid seeing the bottom border 
        android:left="10dp"
        android:right="10dp"
        //android:top="10dp"  Remove this to avoid seeing the top border
    />

    <corners android:radius="5dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle" >
    <padding
        android:bottom="5dp"
        android:left="5dp"
        android:right="5dp"
        android:top="5dp" />

    <solid android:color="#666666" />
</shape>
</item>
</layer-list>

https://stackoverflow.com/a/10133434/1244489

like image 86
Shubhayu Avatar answered Sep 30 '22 11:09

Shubhayu