How do I make a gradient image in Android, like this photo?
I tried this, Hope it will work for you
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:type="radial" android:gradientRadius="250"
android:startColor="#E9E9E9" android:endColor="#D4D4D4" />
</shape>
Related
I'm trying to make gradient background that placed only bottom right.
(Sorry for images because I don't have enough rep for inline)
https://i.stack.imgur.com/ebgWn.jpg
First, I made radial gradient but not perfect
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:centerX="0.9"
android:centerY="1"
android:endColor="#00000000"
android:gradientRadius="40%p"
android:startColor="#BF000000"
android:type="radial" />
</shape>
It looks like:
https://i.stack.imgur.com/JOqFf.jpg
Then, I made linear gradient but still not perfect.
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="315"
android:endColor="#CD000000"
android:startColor="#00FFFFFF"
android:type="linear" />
</shape>
https://i.stack.imgur.com/a0y9C.jpg
Because gradientRadius parameter doesn't work with linear gradient. Are there any starting/ending point parameter for this gradient? Thanks for help!
Best i have tried with
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:centerX="0.8"
android:centerY="1"
android:endColor="#00000000"
android:gradientRadius="80%p"
android:startColor="#BF000000"
android:type="radial" />
And then Wrap your TextView and Tick Icon together inside a layout and set the above background to it..
If you want the exact same effect as you provided in image then you better use a Image or vector file for it .. But the approach will be same setting the background to only Wrapped layout not the Root.
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>
I am trying to make an XML Button, circle shape, which is filled with a gradient color. This color needs to be changed programatically.
Here is an example of what I am trying to achieve.
My attempts to build this have ended up with a gradient background and a solid colored circle. Instead of the gradient circle and transparent background.
I am hoping to be able to use more then 2 colors or a radial gradient for the circle as well. Any help is greatly appreciated.
You can Try with making Drawable XML. Example
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="circle" >
<gradient
android:angle="90"
android:centerColor="#555994"
android:endColor="#b5b6d2"
android:startColor="#555994"
android:type="linear" />
</shape>
Arrange angle based on your requirement.
If you wants to change Color progarmatically then read this:-
How do I programmatically set the background color gradient on a Custom Title Bar?
Belated but can be helpful for someone else
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<gradient android:angle="0" android:endColor="#fff" android:gradientRadius="#dimen/_30sdp" android:startColor="#color/colorPrimaryDark" android:type="radial" />
<size android:width="#dimen/_25sdp" android:height="#dimen/_25sdp" />
</shape>
</item>
Output
Late but someone might get helped. Thanks to #Faizan
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<gradient android:angle="270" android:endColor="#D10719" android:gradientRadius="120dp" android:startColor="#0A5A1B" android:type="linear" />
<size android:width="100dp" android:height="100dp" />
</shape>
</item>
</selector>
Output:
I am trying to make a circle using xml with a halo. The halo would be like it starts with say green color in the center, the greenish color keeps fading and finally at the edges it becomes transparent.
How to go about it?
I am trying to use following:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<gradient android:centerColor="#drawable/light_green" android:gradientRadius="250" android:type="radial"
android:endColor="#android:color/transparent"
android:angle="270"/>
</shape>
Still not able to get the desired effect. Any lead would be helpful.
Try this:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<gradient
android:angle="270"
android:centerColor="#88FF0000"
android:centerX="50%p"
android:centerY="50%p"
android:endColor="#00FF0000"
android:gradientRadius="50%p"
android:startColor="#FFFF0000"
android:type="radial" />
<size
android:height="80dp"
android:width="80dp" />
</shape>
Change color code and change centerColor's alpha code as per your requirement
I am quite new to Android dev, but not Java dev, so doing the logic behind a button is no issue, but styling it is not as easy as css. I have read a couple tutorials on shapes / styles so I kind of know how to do the custom borders and round corners, but I was hoping to see some really good quality examples, like the buttons on the Twitter app http://i.stack.imgur.com/Gip2s.png or the 'debossed' ones on the facebook app.
What I suppose I am really interested in, are using shadows to create effects. Are these done with images, or can you style this in the app?
thanks
for rounded corners create a shape drawable eg. ronded_corner.xml and the angle must be a multiple of 45 degree
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#SomeGradientBeginColor" android:endColor="#SomeGradientEndColor"
android:angle="225"/>
<corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp" android:topRightRadius="7dp"/>
</shape>
then set this Background by android:background:#drawable/ronded_corner
Whenever you create the button in the layout just set the background property of the button as XML, Put this XML file in the drawable folder.
sample XML code i will post here. you can modify and learn in that only.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="270"
android:startColor="#B80000"
android:endColor="#900405"
android:type="linear"
/>
<stroke android:width="1dp" android:color="#900405"/>
</shape>
For rounded corner button, define inset as shown below and adjust radius.
<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="4dp"
android:insetTop="6dp"
android:insetRight="4dp"
android:insetBottom="6dp">
<ripple android:color="?attr/colorControlHighlight">
<item>
<shape android:shape="rectangle"
android:tint="#0091ea">
<corners android:radius="10dp" />
<solid android:color="#1a237e" />
<padding android:bottom="6dp" />
</shape>
</item>
</ripple>
</inset>
For more information http://www.zoftino.com/android-button