Android shadow color for layout - android

I have developed a listView for my app. My UI is simple flat UI, here is a snapshot:
when I searched internet for better interfaces I found this for example:
As you see in this sample, background colors have shadows at the bottom. Is there a way that I can color my Layout background like this? Thanks in advanced.

In order to achieve a shadow effect I'd guess that it's better to use a layer-list with two items, one with the solid color and the second item would be a gradient coming from transparent to a black color with an alpha value.
Here's how this would look like (needs to be placed in res/drawable/):
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#ff33b5e5" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<gradient
android:angle="-90"
android:endColor="#90000000"
android:startColor="#android:color/transparent" />
</shape>
</item>
</layer-list>
Doing it this way, you won't need to "search" for a darker color of your solid color all the time.
Output would look like this:

Create an XML file and named it as "gradient_effect" in Res -> Drawable folder and put below code in it
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#a0a0a0"
android:endColor="#f5f5f5"
android:angle="0"
/>
Now use this file as a background in any of your layout as you can get is like
android:Background= "#Drawable/gradient_effect"
Set above line as an attribute for any of you view or layout in xml file

This can help too!
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:angle="90"
android:endColor="#A2000000"
android:startColor="#android:color/transparent" />
</shape>
</item>

Related

Remove color of the background

i've implemented a #drawable/file (file being a xml file) and i'm trying to use it as a child- view background knowing that the parent-view has already a background so that when looking at the child , we can see the parent background . How can i in this file set the color to null? thanks
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" >
<solid android:color="#color/black" />
</shape>
</item>
<item android:left="2dp">
<shape android:shape="rectangle" >
<solid android:color="#color/white" />
</shape>
</item>
</layer-list>
This is what i 've tried how can i set the attribute color to "no-color"
Here is the image , i still get the black background color but i want the background to be completely transparent :
use transparent color
android:color="#android:color/transparent"

XML Circle with gradient fill Android

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:

Android multi shape drawable

Hi I'm trying to make a drawable which looks like a small vertical line with a circle attached to the bottom of it. I am trying to figure out if creating such a shape in a single xml file is possible (I know I could probably place two shapes on top of each other but I'm trying to avoid doing that)
Here's what I have so far:
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/line">
<shape
android:shape="line"
>
<stroke
android:width="2dp"
android:color="#000000" />
<size android:height="12dp"/>
</shape>
</item>
<item
android:top="5px"
android:id="#+id/circle">
<shape
android:shape="oval"
android:useLevel="false"
android:innerRadius="5dp"
android:thickness="2dp"
>
<solid
android:color="#color/silver_status"
></solid>
<stroke
android:color="#color/silver_status"
android:width="1dp"
/>
</shape>
</item>
</layer-list>
This layers the two images on top of each other (I think) but what I really want is for them to be on top of each other
Anyone know if this is possible/how it can be done?
I ended up solving this simply by using the individual shapes within a linear layout to achieve the affect. Not exactly what I wanted but definitely does the job just fine.

Text with shapes in drawable resource

Can i create text-shape in drawable resource?
I was googling much but found nothing...
Here is my drawable file:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<stroke android:width="3dp" android:color="#QQffQQ"/>
<size android:width="120dp" android:height="120dp"/>
</shape>
</item>
<item android:right="59dp" android:left="59dp">
<shape android:shape="rectangle">
<solid android:color="£22££20"/>
</shape>
</item>
<item android:top="59dp" android:bottom="59dp">
<shape android:shape="rectangle">
<solid android:color="£20££20"/>
</shape>
</item>
<item>
<!--text should be here-->
</item>
</layer-list>
No, you cannot do so. One idea is to set the Drawable as the background for a TextView and then simply set text in the TextView, which will appear above the other layers of your Drawable. Of course, this cannot be used for a splash screen, which requires a drawable resource as mentioned by zyamys in a comment below. An idea for that case is to generate static images with the text you are interested in. This unfortunately does not cover cases where the text is to be dynamic.
You can use vector drawable instead (say by converting from svg file).
Then use vector as one of the layers.
This lets you create a single drawable without any TextViews, so you can easily use it as a windowBackground in your splash screen theme.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:angle="270"
android:startColor="#C3DAE0"
android:endColor="#FFFFFF"
android:type="linear"/>
</shape>
</item>
<item
android:gravity="center"
android:drawable="#drawable/ic_splash_text"/>
</layer-list>
Where ic_splash_text - is a vector drawable with the text.
Not forget to add vectors support if you are4 targeting onto API<21.
For this you have to:
Add to your module build.gradle (app-level):
android {
vectorDrawables.useSupportLibrary = true.
}
Register delegate in a static block of your activity:
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}

Android button styling

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

Categories

Resources