I've seen this subject about puting a border around an android textview, and I used it. But now, I would like to put a border around widgets which are situated into a relative layout. How can I do it?
To add a border to Android TextView we need to create an XML containing shape as a rectangle file under the drawable's folder and set it as background to the TextView. <stroke> tag is used to set the border width and color.
Create a FrameLayout that gets the background color of your border, and a margin or padding of your border width, and place that FrameLayout in your RelativeLayout. Place the TextView in your FrameLayout instead of directly in the RelativeLayout. poof instant border. Show activity on this post.
Create an Android Application with Kotlin support and Empty Activity. Right click on res/drawable folder and click on New -> Drawable Resource File. Give file name as border(or any other name) and Root element as shape. border.
Select the table cells that you want to add a border to (or change the border of). Select the Table Tools / Design tab on the ribbon. Select one of the following in the Draw Borders group: Use Pen Color to change the color of the border.
res/drawable
folder, create a new file background_border.xml
In this file, you will define the background for widget like this:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <!-- This is the stroke you want to define --> <stroke android:width="1dp" android:color="@color/color_stroke"/> <!-- Optional, round your corners --> <corners android:bottomLeftRadius="0dp" android:topLeftRadius="5dp" android:bottomRightRadius="5dp" android:topRightRadius="0dp" /> <!-- Optional, fill the rest of your background with a color or gradient, use transparent if you only want the border to be displayed--> <gradient android:startColor="@android:color/transparent" android:endColor="@android:color/transparent" android:angle="90"/> </shape>
eg. if you want to put your border on a relativelayout:
<RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/background_border" android:padding="15dp"> ... </RelativeLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With