I am creating a sample browser for myself,in which url is set by a edit text that's why i want a edit text must look like a rectangular box like in other browsers...help me out guys???
Add this line to the edittext:
android:background="#drawable/edittext_frame"
And this edittext_frame.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<stroke android:width="1dp" android:color="#color/primary_light" />
<padding android:left="1dp" android:top="1dp" android:right="1dp"
android:bottom="1dp" />
</shape>
Related
im looking for a way, How to add two colors inside a border
just like what this person has done on this image CSS 2-color border but im more intrested to know how you achieve this in android.
The goal is to have something that looks like this https://github.com/lorensr/segmented-control for my app .But with two different colors inside the border that switches between each other when the button is focused.
Have a nice day :)
You can use layer-list and one layer with a gradient background and second layout with solid color with all side padding, like below
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="rectangle">
<gradient
android:angle="180"
android:endColor="#00f"
android:startColor="#f00" />
</shape>
</item>
<item
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp">
<shape
android:shape="rectangle">
<solid android:color="#0f0" />
</shape>
</item>
</layer-list>
In this example, I gave 10dp(in
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp"
) just to see the more clear, you can change value as you want.
You can use a custom xml bacground file like this and use a custom bacground
<item>
<shape android:shape="rectangle">
<corners android:radius="#dimen/_20sdp" />
<gradient
android:angle="180"
android:endColor="#color/yellow_color"
android:startColor="#color/color_red" />
</shape>
</item>
<item
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp">
<shape android:shape="rectangle">
<corners android:radius="#dimen/_20sdp" />
<solid android:color="#color/white_color" />
</shape>
</item>
</layer-list>```
**Two color border with round corner**
enter image description here
How to add this type of frame in android over an image like the picture given
If you are searching for custom border and shape of ImageView
Try this
or
set the below XML to the background of the Image View as Drawable. It works.
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<stroke android:width="1dp" android:color="#000000" />
<padding android:left="1dp" android:top="1dp" android:right="1dp"
android:bottom="1dp" />
</shape>
And then add android:background="#drawable/yourXmlFileName" to your ImageView
I want to add gradient only to the border of my editText , I can add gradient but it takes the entire background . How can I apply gradient only to the border , and the rest should be transparent?
This one does the trick :)
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:angle="45"
android:endColor="#0256FC"
android:centerColor="#0256FC"
android:startColor="#FE00B1" />
<corners android:radius="4dp" />
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<size
android:width="162dp"
android:height="44dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#color/colorWhite" />
<corners android:radius="4dp" />
<size
android:width="50dp"
android:height="50dp" />
</shape>
</item>
</layer-list>
Add the edittext in a layout
Set gradient background color for that layout
Set margin 1dp for edittext.
Set white background for edittext
i think now it's displays like your expectation, thank you
Create your button_border.xml and keep it within drawable.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- view border color and width -->
<stroke
android:width="1dp"
android:color="#color/white" >
</stroke>
<!-- The radius makes the corners rounded -->
<corners
android:radius="2dp" >
</corners>
</shape>
Now set your editText background as follows :
android:background="#drawable/button_border"
I am making a background shape for EditText - xml below:
<?xml version="1.0" encoding="UTF-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/WhiteSmoke"/>
<stroke android:width="1dp" android:color="#color/aadhaar_logo_brown" />
<padding android:left="2dp" android:top="2dp" android:right="2dp" android:bottom="2dp" />
<corners android:topRightRadius="10dp" />
<gradient android:startColor="#color/White"
android:centerColor="#color/White"
android:endColor="#color/White"
android:angle="0"/>
</shape>
However I require an image on the right hand side of the EditText to indicate mandatory field. I tried adding the image programmatically but the image does not show up in the runtime
((EditText) findViewById(R.id.txt_enduser_name)).setCompoundDrawables(null, null, getResources().getDrawable(R.drawable.ic_mandatory_text_field), null);
Please help
You need to provide an "intrinsic size" to the shape:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
...
<size android:height="20dp" android:width="20dp"/>
</shape>
Then, you can just set it as the drawableRight:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableRight="#drawable/ic_mandatory_text_field"/>
I want to use border image is below :
set border for Layout ...?
Should i do it ?
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<stroke android:width="1dp" android:color="#000000" />
<padding android:left="1dp" android:top="1dp" android:right="1dp" android:bottom="1dp" /></shape>
Save this file in as customborder.xml in drawbale folder. In you layout file add this line android:background="#drawable/customborder"
You can make a 9-patch image as apply it as the background. Make the middle transparent and fill the border the way you want.
Here is the official documentation: http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
What you can do is create an custom drawable shape that will apply as the background of ImageView which will create a border.
Something like below xml, you can customize it yourself. Put it in drawable/image_border.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#FFFFFF" />
<stroke
android:width="1dp"
android:color="#000000" />
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
</shape>
Apply it as ImageView's background. It should create a border for your ImageView.
first create simple border.xml and save in to drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" >
<corners android:radius="15dip" />
<solid android:color="#00000000" />
<stroke android:width="2dp" android:color="#000000"/>
</shape>
</item>
</layer-list>
then after set background of Linear/Relative layout
android:background="#drawable/imageee_color"