Trapezoid drawable like in the picture? - android

I want to design a xml layout as in the picture. So far I have rectangle shape how to make that sharp corners from xml.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="#+id/listview_background_shape">
<stroke android:width="0dp" android:color="#4c71f5" />
<padding android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp" />
<corners android:radius="2dp" />
<solid android:color="#color/colorAccent" />
</shape>

You can use something like below:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="270" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
and refer to this link, Good Example

Related

How can I create Samsung's "Fix Now" button with gradient animation in Android Studio

How can I create this awesome button with gradient animation? I attached a GIF.
Make a drawable for background and set in on back
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners
android:radius="14dp"
/>
<gradient
android:angle="45"
android:centerX="34%"
android:startColor="#56ab2f"
android:endColor="#a8e063"
android:type="linear"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<size
android:width="270dp"
android:height="60dp"
/>
<stroke
android:width="3dp"
android:color="#1d5b01"
/>
</shape>

Simple customized button in android

I've used the tutorial in this link which demonstrates a great way of using different colors for buttons.
He has demonstrated all the colors for the buttons as below
Ex:: for red He mentions as
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<solid
android:color="#ef4444" />
<stroke
android:width="1dp"
android:color="#992f2f" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#ef4444"
android:endColor="#992f2f"
android:angle="270" />
<stroke
android:width="1dp"
android:color="#992f2f" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>
But he has not mentioned the color for Orange in the
Can someone give a demonstration with Orange color
Specifications must be same as the ones mentioned for other colors
but color must be orange
Check all color codes here
just replace your desired color in
<item>
<shape>
<gradient
android:startColor="#ef4444"
android:endColor="#992f2f"
android:angle="270" />
<stroke
android:width="1dp"
android:color="#992f2f" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
These two lines
android:startColor="#ef4444"
android:endColor="#992f2f"
padding is the inside spacing and stroke is the width of boundary of button. just replace the colors in gradient tag and make your desired button.
I just wanted to post the code for answer ( thanks to Brontok & Tanis .7x)
I found the solution::
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<solid
android:color="#ff8800" />
<stroke
android:width="1dp"
android:color="#992f2f" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#ff8800"
android:endColor="#992f2f"
android:angle="270" />
<stroke
android:width="1dp"
android:color="#992f2f" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>

Gradient type error

I am trying to create a glow effect by using a gradient.
In my XML I have this...
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<solid android:color="#7AD8FF" />
<gradient android:startColor="#android:color/transparent" android:endColor="#7AD8FF" android:type="radial"/>
<stroke android:width="0dp" android:color="#7AD8FF"/>
<corners android:radius="20dp" />
<padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
</shape>
</item>
<item>
<shape>
<solid android:color="#android:color/transparent"/>
<stroke android:width="0dp" android:color="#D1D1D1" />
<corners android:radius="0dp" />
<padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
</shape>
</item>
When I try to set "android:type="radial"", it causes an error...
...Any ideas?
Try specifying android:gradientRadius:
<gradient
android:startColor="#android:color/transparent"
android:endColor="#7AD8FF"
android:type="radial"
android:gradientRadius="100"
/>

Android Clip image to bounds

I have a custom #drawable as a background for a button. I have a bitmap and a shape on top of it. The problem is that the corners of the bitmap are not clipping to the shape, like illustrated bellow.
My question is: Is there a way to clip the bitmaps to the bounds the shape? How?
EDIT: Here is the XML:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<solid
android:color="#8F8F8F" />
<stroke
android:width="1dp"
android:color="#8f8f8f" />
<corners
android:radius="8dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<layer-list>
<item>
<!-- <nine-patch android:src="#drawable/button"/>-->
<bitmap android:src="#drawable/background_image" />
</item>
<item>
<shape>
<solid android:color="#android:color/transparent" />
<stroke android:width="1dp" android:color="#8f8f8f" />
<corners android:radius="12dp" />
<padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
</shape>
</item>
</layer-list>
</item>
</selector>
You will have to change alpha level at the corners or use Draw 9-patch tool to create the background

Android: Spinner background with a drop down shape

Currently I am using this xml for the background of my spinner:
<item android:state_pressed="true" >
<shape>
<gradient
android:startColor="#008000"
android:endColor="#7FFF00"
android:angle="270" />
<stroke
android:width="1dp"
android:color="#A8A8A8" />
<corners
android:radius="6dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:endColor="#ffc536"
android:startColor="#ffe9b3"
android:angle="270" />
<stroke
android:width="1dp"
android:color="#e4962d" />
<corners
android:radius="6dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
And I like the color and the gradient however there is no indicator that there it is a drop down menu. Is there anyway to add a image or a shape to the right side to indicate a drop down menu? I found this easier then make 9-patch files.
You need to create a custom component and write an XML file and a UI element for it to implement this.
Simply treat the UI element as a drop-in version of what you're trying to implement.
Hope this helps!
i know that this question is old but i resolve in this way :
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#FFFFFF" />
<stroke
android:width="1dp"
android:color="#color/green" />
<corners android:radius="3dp" />
</shape>
</item>
<item>
<bitmap
android:gravity="right|center"
android:src="#drawable/ic_arrow_drop_down" />
</item>

Categories

Resources