Add border around relativelayout in android with custom background

How to set stroke in android activity using Relativelayout example tutorial.

Border is used to separate the complete layout screen from mobile screen ending corners. When we have enter border inside relative layout it will make the activity screen non markable to phone corners. So we can add custom border including custom background using custom external layout xml file into our android project. So here is the complete step by step tutorial for Add border around relativelayout in android with custom background.

android-project-download-code-button

How to Add border around relativelayout in android with custom background.

Code for MainActivity.java file.

package com.addborderaroundrelativelayout_android_examples.com;
import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 }
}

Code for activity_main.xml layout file.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.addborderaroundrelativelayout_android_examples.com.MainActivity"
 android:background="@layout/relativelayout_custom_border" >

</RelativeLayout>

 

Code for relativelayout_custom_border.xml.php file.

 <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
 <shape android:shape="rectangle">
 <solid android:color="#d0d0d0"/>
 <stroke
 android:width="5dp"
 android:color="#00dbfb" ></stroke>
 </shape>
 
</item>
</selector>

Screenshot :

Add border around relativelayout in android with custom background

Click here to download Add border around relativelayout in android with custom background project.

Leave a Reply

Your email address will not be published. Required fields are marked *