this is my xml file which add border around linear layout how do i add gradient color effect code inthis code? i want replace this color #C0C0C0 with gradiend color
below is my code
<?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="#000000" />
</shape>
</item>
<item
android:left="1dp"
android:right="1dp"
android:top="2dp"
android:bottom="2dp" >
<shape android:shape="rectangle">
<solid android:color="#C0C0C0" />
</shape>
</item>
</layer-list>
i want to add this code in my border .xml file how i merge??
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#fefdfe"
android:endColor="#e8e3ec"
android:angle="90" />
</shape>
fill layout with gradient:
<?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:startColor="#4fc939"
android:centerColor="#0c87c5"
android:endColor="#b4ec51"
android:angle="180" />
</shape>
</item>
Just replace
<shape android:shape="rectangle">
<solid android:color="#C0C0C0" />
</shape>
with your gradient shape.
Try this:-
<shape android:shape="rectangle">
<gradient
android:startColor="#5a5a5a88"
android:endColor="#14141488"
android:angle="270" android:centerX="0.25"/>
</shape>
Related
Hi I am trying to add a border to a view which has yellow border but it also has a black border on both sides of primary border.
Any ideas
Try this drawable layout for border on top and bottom
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<stroke
android:width="2dp"
android:color="#ffff00" />
<solid android:color="#000000" />
</shape>
</item>
<item
android:bottom="2dp"
android:top="2dp">
<shape android:shape="rectangle">
<stroke
android:width="2dp"
android:color="#000000" />
</shape>
</item>
</layer-list>
Try this for left and right border
<?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="#ffff00"/>
</shape>
</item>
<item android:left="4dp">
<shape android:shape="rectangle">
<solid android:color="#000000"/>
</shape>
</item>
<item android:right="4dp">
<shape android:shape="rectangle">
<solid android:color="#000000"/>
</shape>
</item>
</layer-list>
I am looking for some tutorial or some reference which can help me to create some custom shapes like below-mentioned shape.Background Shape
I have tried creating a shape using the standard shape in android xml, but I am not able to find an appropriate solution for it.
It would be a good help if someone can explain how can I achieve this.
Try using this layer-list in drawable folder
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" android:tint="#0000ff">
<padding android:bottom="5dp" android:left="5dp" android:right="5dp" android:top="5dp"></padding>
</shape>
</item>
<item>
<bitmap
android:gravity="right"
android:src="Your_blur_backgound_image" />
// you can use any other image here
</item>
You should use a <layer-list>, try this:
<?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="#ffffff"/>
<size android:height="30dp" android:width="40dp"/>
</shape>
</item>
<item>
<shape
android:shape="oval">
<gradient
android:type="radial"
android:gradientRadius="15dp"
android:endColor="#ffffff"
android:startColor="#0000ff" />
</shape>
</item>
<item>
<inset
android:insetLeft="5dp"
android:insetRight="15dp"
android:insetTop="5dp"
android:insetBottom="5dp">
<shape android:shape="rectangle">
<solid android:color="#ff0000"/>
</shape>
</inset>
</item>
</layer-list>
Result:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="0"
android:centerX="0.1"
android:centerY="0.1"
android:centerColor="#1976d2"
android:startColor="#00e5ff"
android:endColor="#6200ea"
android:gradientRadius="100"
android:type="linear"/>
<padding android:left="5dp"
android:top="4dp"
android:right="4dp"
android:bottom="4dp" />
<corners android:radius="6dp" />
</shape>
I need to change the background color of a button using shapes.
`
<?xml version="1.0" encoding="utf-8"?/>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_active="true">
<shape android:shape="rectangle">
<solid android:color="#color/blue3"/>
<stroke android:color="#color/white1" android:width="2dp" />
<corners android:radius="8dp" />
</shape>
</item>
</selector>
`
I am trying to set blue3 color using solid but it's not appearing in view. Please make me correct if i am trying to do it incorrect way.
Use this file in drawable
<?xml version="1.0" encoding="utf-8"?>
<item>
<layer-list >
<item>
<shape>
<solid android:color="#d4d4d4"></solid>
<corners android:radius="2dp"></corners>
</shape>
</item>
<item android:right="2dp" android:bottom="2dp" android:left="1dp" android:top="1dp">
<shape>
<solid android:color="#ff0000"></solid>
<corners android:radius="2dp"></corners>
</shape>
</item>
</layer-list>
</item>
and set Button background from drawable
Hope this will help!
Here is the solution of this question.
`
<?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/blue3" />
<corners android:radius="8dp" />
</shape>
</item>
</layer-list>
`
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="oval"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<solid android:color="#ffffff"/>
<stroke android:width="30dp"
android:color="#51000000"
/>
</shape>
It gives a "half-inner-half-outer" stroke.
What I need is outer semitransparent stroke only. Can it be done?
What I have is
What I need is
Thanks
you can check this shape created using layer list with it's items.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape android:shape="oval" >
<solid android:color="#fff" />
</shape>
</item>
<item >
<shape android:shape="oval">
<solid android:color="#android:color/transparent" />
<stroke
android:width="50dp"
android:color="#30000000" />
</shape>
</item>
</layer-list>
if you add alpha for stroke color the inner half is without transparent and outer is transparent.this is how stroke color works.if you don't want inner circle use color without Alpha and adjust Hexcode.
Try adding android:innerRadius="0dp" for shape attribute -
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="oval"
xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="0dp"
>
<solid android:color="#ffffff"/>
<stroke android:width="4dp"
android:color="#51000000"
/>
</shape>
This is Android studio XML preview bug.look like The image you shown above from Android studio xml preview.actually there is no inner and outer layer.
I've found no way to do that other than the following:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape android:shape="oval">
<solid android:color="#android:color/transparent" />
<stroke
android:width="#dimen/stroke_width"
android:color="#33000000" />
</shape>
</item>
<item >
<shape android:shape="oval" >
<solid android:color="#fff" />
<stroke
android:width="#dimen/stroke_width"
android:color="#android:color/transparent">
</stroke>
</shape>
</item>
</layer-list>
Try This: (Change dimens and colors to fit your needs)
<?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="#dimen/default_stroke_size_small" android:color="#color/colorDimBlack"/>
</shape>
</item>
<item>
<shape android:shape="oval">
<stroke android:width="#dimen/default_stroke_size_small" android:color="#android:color/transparent"/>
<solid android:color="#color/colorWhite"/>
</shape>
</item>
</layer-list>
update your code to this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#ffffff" />
<stroke
android:width="30dp"
android:color="#000000" /> <--- this line you have to change
</shape>
You are missing one f in your first color. Thus it's creating a half visible pattern
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="oval"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<solid android:color="#fffffff"/>
<stroke android:width="30dp"
android:color="#51000000"
/>
</shape>
Background
I'm trying to make a (fake) shadow below a view, so that the layers would be vertical in this manner:
a line of color "#43000000" with a height of "1dp"
below the line, a gradient that starts from the top with color "#1A000000" and ends with color "#00000000", and is of a height of "8dp".
The problem
For some reason, I can't draw the line correctly.
No matter what I do, the line for some reason takes the whole space, while the gradient seems fine.
What I tried
I tried using "line" as the shape and also "rectangle". I also tried using "stroke" instead of "solid", tried adding padding and margins...
Here's the XML of the drawable file:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<size android:height="1dp" />
<solid android:color="#43000000" />
</shape>
</item>
<item android:top="1dp">
<shape android:shape="rectangle" >
<gradient
android:angle="270"
android:endColor="#00000000"
android:startColor="#1A000000" />
<size android:height="8dp" />
</shape>
</item>
</layer-list>
Again, this is not the only thing I've tried. It's just my first attempt.
The question
How can I fix this XML ? what is causing it to happen?
Here's what I've found to be working:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:bottom="8dp">
<shape android:shape="rectangle" >
<size android:height="1dp" />
<solid android:color="#43000000" />
</shape>
</item>
<item android:top="1dp">
<shape
android:dither="true"
android:shape="rectangle" >
<gradient
android:angle="270"
android:endColor="#00000000"
android:startColor="#10000000" />
<size android:height="8dp" />
</shape>
</item>
</layer-list>
Tried with this,may it fulfill your need with gradient
<?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="#e040fb"/>
<corners android:radius="2dp" />
</shape>
</item>
<item
android:left="0dp"
android:right="0dp"
android:top="0dp"
android:bottom="2dp">
<shape android:shape="rectangle">
<solid android:color="#E1BEE7"/>
<corners android:radius="2dp" />
<gradient
android:angle="270"
android:endColor="#e1bee7"
android:startColor="#e040fb" />
</shape>
</item>
</layer-list>
You can change the heights in this and get what you want
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:height="10dp"
android:gravity="bottom">
<shape
android:shape="oval">
<solid android:color="#color/shadow_color" />
</shape>
</item>
<item android:right="20dp" android:left="20dp" android:bottom="12dp"
android:top="10dp">
<shape
android:shape="rectangle">
<solid android:color="#color/border_color"/>
<corners android:radius="20dp"/>
</shape>
</item>
<item android:right="30dp" android:left="30dp" android:bottom="23dp"
android:top="20dp">
<shape
android:shape="rectangle">
<solid android:color="#color/base_color"/>
<corners android:radius="15dp"/>
</shape>
</item>
</layer-list>