Thursday, February 21, 2019

Make border for view in Android

We want to create border for textView, button or layout.
Right click to folder src, new, folder, name it drawable.
Right click to drawable, new, Android XML File, name it border
Copy these line in to border.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1dip"
 android:color="#4b5320" />
<solid
android:color="#ffffff" />

</shape>

When want to make border for a view, add this line in to xml code.
android:background="@drawable/border"
A TextView with border look like this.
You can also use this for button, layout.

Change hex code at android:color="#4b5320, if want another color.
If want round corner, add this line to border.xml.
<corners android:radius="8dp"/>

No comments:

Post a Comment