<?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>
Related
I'm trying to create a drawable with two shapes next to each other using layer-list, how would I do it?
You can use the following code to have the drawable you want(Change the colors and height as you want)
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:gravity="center">
<shape android:shape="rectangle">
<size
android:width="5dp"
android:height="5dp" />
<solid android:color="#color/colorAccent"/>
</shape>
</item>
<item android:gravity="right">
<shape android:shape="rectangle">
<size
android:width="1dp"
android:height="5dp" />
<solid android:color="#color/colorPrimary"/>
</shape>
</item>
</layer-list>
I need to create Edittext drawable background with %100 percent transparent and has only colored bottom line 2dp. Is there any way to make this component.
The bellow code with constant background. I need transparent background.
<?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/colorPrimary2" />
<padding android:bottom="2dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle" >
<solid android:color="#color/background" />
</shape>
</item>
</layer-list>
Here you go:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#android:color/transparent" /> <!--background color -->
</shape>
</item>
<item
android:top="-3dp"
android:right="-3dp"
android:left="-3dp">
<shape>
<solid android:color="#android:color/transparent" />
<stroke
android:width="2dp"
android:color="#000" />
<!-- color and size of the border -->
</shape>
</item>
</layer-list>
There is color for a transparency in android. 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="#FFffffff" />
<padding android:bottom="2dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle" >
<solid android:color="#color/background" />
</shape>
</item>
</layer-list>
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>
`
I am trying to create a following shape in android.
I tried following code but it's only for changing the corners
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#ffffff" />
<gradient
android:startColor="#00EBCF"
android:endColor="#00BEEC"
android:angle="180"
android:type="linear" />
<corners
android:bottomLeftRadius="80dp"
android:bottomRightRadius="80dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp" />
What do I need to make changes in code to achieve the above shape?
Edit1
As per the answer I used following code (modifications in layout height):
<?xml version="1.0" encoding="utf-8"?>
</shape>
</item>
<item
android:width="1500dp"
android:height="200dp"
android:top="95dp">
<shape android:shape="oval">
<solid android:color="#36D6E9" />
</shape>
</item>
But when I am using this layout as a background for LinearLayout. It's showing me this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#drawable/header_shape_rect">
use this as an example
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:height="200dp">
<shape android:shape="rectangle">
<solid android:color="#ccc"/>
</shape>
</item>
<item android:height="200dp" android:top="95dp" android:width="1500dp" >
<shape android:shape="oval">
<solid android:color="#ccc"/>
</shape>
</item>
</layer-list>
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>