how to make gradient exactly like these drawable in android - android

NOTE : updated question !
i want to make gradiend as mentioned in the pic
the centered gray is a line i want it to be merged with both right left
Solution tried
Android drawable with background and gradient on the left
i couldnt find more about custom drawable gradient how i need
<shape android:shape="rectangle">
<gradient
android:angle="0"
android:centerColor="#color/white"
android:endColor="#color/gray"
android:startColor="#color/gray"
android:type="linear"
/>
</shape>
i have these two images and want to make them with drawable ..
thanks in advance ..
PS : I have also tried the answer i got against my question but i think this gradient isnt possible i have been waiting since 3 months for solution.

Try to use type as radial :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:useLevel="false">
<size
android:width="48dip"
android:height="48dip" />
<gradient
android:centerColor="#android:color/white"
android:centerY="0.5"
android:gradientRadius="180"
android:type="radial"
android:useLevel="false" />
</shape>

try this and change color what you want
android:background:"#drawable/color_grad"
color_grad.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:centerColor="#FAFAFA"
android:endColor="#C7C7C7"
android:startColor="#C7C7C7"
android:type="linear"
android:angle="270"/>
<corners android:radius="0dp" />

android:background="#drawable/gradient"
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#C3C3C3"
android:endColor="#00000000"
android:angle="45"/>
</shape>

Related

How Can I set color And Angle like That Using XMl on Android Studio

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="5dp"/>
<gradient android:angle="45"
android:type="linear"
android:startColor="#999999"
android:endColor="#00a650" />
</shape>
How Can I make an XML file like this image? Android studio I tried But couldn't.
Angle Should be 30% And make a border diagonally.
Image LInk https://i.stack.imgur.com/cJETA.jpg
You just need to set centerX or centerY together with centerColor (see suggestion below)
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="5dp"/>
<gradient
android:angle="45"
android:centerColor="#999999"
android:centerX="0.7"
android:endColor="#00a650"
android:startColor="#999999"
android:type="linear"/>
</shape>

How to add second gradient wave?

I added such gradient as a background for my screen
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="45"
android:startColor="#0019A8"
android:centerColor="#4C5CB1"
android:endColor="#0019A8"
android:type="linear" />
</shape>
there is a result that I got
So, at the middle I have one gradient stripe, what I actually need is - two stripes, first one closer to right left edge and second one to left bottom edge.
But, gradient give just 3 options for set color start, center, end.
So, question is - how to do it?
Use layer list.
<?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:startColor="#0019A8"
android:centerColor="#4C5CB1"
android:endColor="#0019A8"
android:type="linear" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<gradient
android:type="linear"
android:gradientRadius="100"
android:startColor="#14B2FF"
android:endColor="#android:color/transparent"
android:centerX="0.5"
android:centerY="0.75"/>
</shape>
</item>
</layer-list>
Result

How to center the gradient color in android

Hi I am trying to gradient in android.
I am trying the following code
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#EF5350"
android:centerColor="#FFEBEE"
android:endColor="#EF5350"
android:angle="-270" />
</shape>
Result:
I want to increase the size of white in center. Please help me to solve my issue.
Try this :
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:top="50dp">
<shape android:shape="rectangle">
<gradient
android:startColor="#EF5350"
android:endColor="#EF5350"
android:centerColor="#FFFFFF"
android:angle="270"/>
<size
android:height="100dp"
android:width="80dp"/>
</shape>
</item>
<item
android:bottom="50dp">
<shape android:shape="rectangle">
<gradient
android:startColor="#EF5350"
android:endColor="#FFFFFF"
android:centerColor="#FFFFFF"
android:angle="270"
/>
<size
android:height="100dp"
android:width="80dp"/>
</shape>
</item>
</layer-list>
You need to specify type inside the gradient tag,
For e.g. in my case I have defined radial for center gradient effect,
android:type="radial"
I have created gradient shape (centergradietbg.xml) with center gradient effect, look it my code
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:centerColor="#c1c1c1"
android:endColor="#4f4f4f"
android:gradientRadius="400"
android:startColor="#c1c1c1"
android:type="radial" >
</gradient>
</shape>
Use this xml in your layout background using
android:background="#drawable/centergradietbg"

Android rectangle background gradient

I want to crate a background gradient that goes from the inside to outside. And at the outside it should be getting darker. Here is an image:
Can anyone give me some advice how I can create something like that?
Or should I take an image for this? If yes, what's about different screen resolutions? Or about landscape / portrait modus?
use this change color as required
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<gradient
android:type="radial"
android:startColor="#f15330"
android:endColor="#da0000"
android:gradientRadius="150dp"
/>
<size android:height="400dp"
android:width="250dp"/>
</shape>
Yes , you can use nine patch image to achieve for this type gredient
but if you want use gredient then i think this will be help for you..
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<gradient
android:type="radial"
android:centerX="50%"
android:centerY="50%"
android:startColor="#FFff0000"
android:endColor="#FF000000"
android:gradientRadius="100"/>
</shape>
and this is olnline tool where you can create gredient and you can grab the code using android tab..
How you want is it like cardview?Or you can try with this also,
<?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="360"
android:centerColor="#e95a22"
android:endColor="#ff00b5"
android:gradientRadius="360"
android:startColor="#006386"
android:type="sweep" />
<stroke
android:width="2dp"
android:color="#ff207d94" />
</shape>
</item>
<item
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp">
<shape android:shape="rectangle" >
<solid android:color="#fff" />
</shape>
</item>
</layer-list>

Layout with different colors

I'd like to have a background color of a RelativeLayout similar to that of an image shown in the link below. Ignore the black strip in the bottom half of the image.
I don't want to use the image as a background of the layout. Can you give me an idea of how to proceed?
You can use gradient. Set different gradient in selector as you want. Done!
GradientDrawable.class
This is what you want, set your colors. Enjoy!
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:bottom="30dp">
<shape android:shape="rectangle" >
<corners
android:topRightRadius="8dip"
android:topLeftRadius="8dip" />
<gradient
android:startColor="#030303"
android:endColor="#3B3B3B"
android:angle="270" />
</shape>
</item>
<item android:top="30dp" >
<shape android:shape="rectangle" >
<corners
android:bottomLeftRadius="8dip"
android:bottomRightRadius="8dip" />
<gradient
android:startColor="#4B5057"
android:endColor="#4B5059"
android:angle="270" />
<size android:height="30dp" />
</shape>
</item>
</layer-list>
just try with shape file structure. I think this may give the solution.
//save this below code as gradient and use as background of your layout as
android:background="#drawable/gradient"
//gradient.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#232323" android:endColor="#4B5059"
android:angle="270"/>
</shape>

Categories

Resources