Add gradient in edit text border in android - android

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"

Related

Rectangle in xml without bottom side

I have a shape rectangle in my drawable like this
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="2dp"
android:topRightRadius="0dp"
android:bottomRightRadius="0dp"
android:bottomLeftRadius="0dp"/>
<stroke
android:width="1dp"
android:color="#android:color/white"
/>
</shape>
How, can I hide bottom line ?
<?xml version="1.0" encoding="UTF-8"?>
<!-- inset is used to remove border from top, it can remove border from any other side-->
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetTop="-2dp">
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="#+id/rectangle">
<stroke android:width="1dp" android:color="#b7b7b7" />
<corners android:bottomRightRadius="5dp" android:bottomLeftRadius="5dp"/>
<solid android:color="#454444"/>
</shape>
</inset>
use this code
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- the line -->
<item>
<shape>
<solid android:color="#yourColor"
/>
</shape>
</item>
<!-- This is full view -->
<item android:bottom="10dp">
<shape>
<solid android:color="#backGroundColor" />
</shape>
</item>
this will add a 10dp height line at bottom of your view , u can change size of the line with
<item android:bottom="10dp">
and change color too
good luck

android - borders seems to be cut

I set the Root Layout background as black colour with corner radius and padding. I set the child layout background as white colour only so the corners seems to be removed. I mean it white colour as overlay of the black. I found one solution for this i.e., we should maintain one more xml like root layout background. Is there any good solution instead of this?
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#color/black_color" />
<corners android:radius="10dp" />
<padding
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp" />
</shape>
You need to create another XML file for the white background and give corner top radius to left-right only. And apply this background to the child view.
try this or a modification of this.Just modify the lines and other things as you need it.I needed a black bar at the top.I just modified that to white for your use.But you will still ahve trim your image to be smaller than the overall border.
what if you put your image as
android:scaleX="0.95"
android:scaleY="0.95"
the drawable code:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:bottom="40dp">
<shape android:shape="rectangle" >
<solid android:color="#FFFFFF" />
<corners android:radius="20dp" />
<stroke
android:width="1dp"
android:color="#7F7F7F" />
</shape>
</item>
<item android:top="40dp">
<shape android:shape="rectangle" >
<solid android:color="#FFFFFF" />
<corners android:radius="20dp" />
<stroke
android:width="1dp"
android:color="#7F7F7F" />
</shape>
</item>
<item
android:bottom="40dp"
android:left="1dp"
android:right="1dp"
android:top="24dp">
<shape android:shape="rectangle" >
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>

round corners with border color

I am using the following code to get rounded corners as well as a colored outline:
<?xml version="1.0" encoding="UTF-8"?>
<gradient
android:startColor="#color/white"
android:endColor="#color/white" />
<corners
android:bottomRightRadius="2dp"
android:bottomLeftRadius="2dp"
android:topLeftRadius="2dp"
android:topRightRadius="2dp"/>
<stroke
android:width="5dip"
android:color="#color/black" />
The image displays what I'm getting right now. Due to the stroke, the rounded corners only lie on the outer edge of the layout and the inner edge of the black outline makes a rectangle with sharp edges. How can I convert the sharp edges to rounded corners?
Use the <shape> tag to create a drawable in XML with rounded corners. (You can do other stuff with the shape tag like define a color gradient as well).
Following code may help you:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffffff"/>
<stroke android:width="3dp"
android:color="#ff000000"
/>
<padding android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp"
/>
<corners android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
</shape>
Use this customize according to your need.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#android:color/transparent" />
<stroke
android:width="4dp"
android:color="#android:color/holo_blue_light" />
<corners android:radius="6dp" />
</shape>

How to set image border for Layout (RelativeLayout) in Android?

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"

How to position radial gradient background

How can I position a radial gradient shape as background in a LinearLayout ? Here is what I presently have :
The shape :
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:endColor="#e6e6e6"
android:gradientRadius="800"
android:startColor="#fafaf9"
android:type="radial"/>
</shape>
The LinearLayout :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/accueil_bg_gradient">
</LinearLayout>
I just want to have my gradient starting from the left upper corner of the screen, and ending at the right lower corner.
Thanks a lot !
You can move the middle of the radial gradient at a different position of the drawable using "centerX" and "centerY" attributes of the gradient. They are a floating point values ranging from 0 to 1.0 where (values of centerX,centerY accordingly) 0,0 is upper left and 1,1 is bottom right corner.
Default is 0.5,0.5 which is the middle of the drawable / assigned space.
Example for a 100px long (radius), black-white gradient whose middle starts at upper left corner would be:
<shape android:shape="rectangle">
<gradient
android:type="radial"
android:startColor="#ffffff"
android:endColor="#000000"
android:gradientRadius="100"
android:angle="270"
android:centerX="0"
android:centerY="0"/>
</shape>
set this as background mybackground.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" android:layout_width="wrap_content">
<stroke android:width="10dp" android:color="#color/darkBlue" />
<solid android:color="#00000000" />
<padding android:left="1dp" android:top="1dp" android:right="1dp"
android:bottom="1dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<gradient android:startColor="#color/grayBlue"
android:endColor="#color/lightBlue" android:angle="270"
android:centerColor="#color/lightBlue" />
<!-- border width and color -->
<stroke android:width="1dp" android:color="#FFDDDDDD" />
<padding android:left="10dp" android:top="8dp" android:right="10dp"
android:bottom="8dp" />
</shape>
</item>
</layer-list>

Categories

Resources