I need to get the below shape in Android I can't get this as using Constraint layout, refer my code.
<item>
<shape android:shape="rectangle">
<solid android:color="#color/theme_dark"/>
<corners android:topLeftRadius="0dp" android:topRightRadius="0dp"
android:bottomLeftRadius="500dp" android:bottomRightRadius="0dp"/>
</shape>
</item>
</selector>
sample i need
Try this drawable xml 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="#color/white"/>
</shape>
</item>
<item
android:bottom="0dp"
android:left="-10dp"
android:right="-200dp"
android:top="-400dp">
<shape android:shape="oval">
<solid android:color="#color/purple_500"/>
</shape>
</item>
</layer-list>
Output for above drawable is:
If set background to half part of screen:
If set background to full screen:
I want to define a backgound image using XML. Like 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="#C0C0C0" />
<corners android:radius="5dp"/>
</shape>
</item>
<item android:right="1dp" android:left="1dp" android:bottom="3dp">
<shape
android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<corners android:radius="5dp"/>
</shape>
</item>
</layer-list>
For some visual reasons, I want to draw circles in each corner of this background with XML.
Is there a possibility to do so? For example like this:
You can use RoundedImageView class,
compile 'com.makeramen:roundedimageview:2.3.0'
Look at this link
RoundedImageView
I have been all morning trying to do an custom shape like as facebook button like this:
But I'm trying to do it customizable, so in the future I could change the icon for example, but I'm going crazy.
How I can make a button like this? Only the right part must be pressed, the left with the icon must be static although it will be pressed.
I have this for the left side:
<?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/gecas_blue"/>
<corners
android:topLeftRadius="4dp"
android:topRightRadius="4dp"/>
<size
android:height="#dimen/bt_icon_size"
android:width="#dimen/bt_icon_size"
/>
</shape>
</item>
<item
android:left="10dp">
<shape android:shape="rectangle">
<solid
android:color="#color/gecas_blue"/>
<size
android:height="#dimen/bt_icon_size"
android:width="#dimen/bt_icon_size"
/>
</shape>
</item>
<item android:drawable="#android:drawable/ic_input_add">
<size
android:height="#dimen/bt_icon_size"
android:width="#dimen/bt_icon_size"
/>
</item>
</layer-list>
And this for the right, but I know how to continue:
<?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/gecas_blue"/>
<corners
android:topLeftRadius="4dp"
android:topRightRadius="4dp"/>
</shape>
</item>
<item
android:right="10dp">
<shape android:shape="rectangle">
<solid
android:color="#color/gecas_blue"/>
</shape>
</item>
</layer-list>
This is the most similar library that I've found.
Flat Buttons
Try https://github.com/medyo/fancybuttons it almost fit what you try to do.
Is it possible to define a shape like shown on the following image:
I tried a layer-list but I could not find a solution close to what I am looking for.
I want to use the resulting shape as a background image to a RelativeLayout with a transparency.
Any hints are appreciated! Thank you.
Here is the shape you asked for:
<?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:width="250dp"
android:height="100dp" />
<solid android:color="#ffffff" />
</shape>
</item>
<item
android:top="0dp">
<shape android:shape="line">
<stroke
android:width="25dp"
android:color="#000000" />
</shape>
</item>
<item
android:right="0dp"
android:left="150dp">
<shape android:shape="oval">
<solid android:color="#000000" />
</shape>
</item>
</layer-list>
Screenshot:
How do you add a background image to a shape? The code I tried below but no success:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
//here is where i need to set the image
<solid android:color="#drawable/button_image"/>
<corners
android:bottomRightRadius="5dp"
android:bottomLeftRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp"/>
</shape>
Use following layerlist:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" android:padding="10dp">
<corners
android:bottomRightRadius="5dp"
android:bottomLeftRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp"/>
</shape>
</item>
<item android:drawable="#drawable/image_name_here" />
</layer-list>
I used the following for a drawable image with a circular background.
<?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="#color/colorAccent"/>
</shape>
</item>
<item
android:drawable="#drawable/ic_select"
android:bottom="20dp"
android:left="20dp"
android:right="20dp"
android:top="20dp"/>
</layer-list>
Here is what it looks like
This is a circle shape with icon inside:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/ok_icon"/>
<item>
<shape
android:shape="oval">
<solid android:color="#color/transparent"/>
<stroke android:width="2dp" android:color="#color/button_grey"/>
</shape>
</item>
</layer-list>
This is a corner image
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#drawable/img_main_blue"
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />
<item>
<shape
android:padding="10dp"
android:shape="rectangle">
<corners android:radius="10dp" />
<stroke
android:width="5dp"
android:color="#color/white" />
</shape>
</item>
</layer-list>
I used the following for a drawable image with a border.
First make a .xml file with this code 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="oval">
<solid android:color="#color/orange"/>
</shape>
</item>
<item
android:top="2dp"
android:bottom="2dp"
android:left="2dp"
android:right="2dp">
<shape android:shape="oval">
<solid android:color="#color/white"/>
</shape>
</item>
<item
android:drawable="#drawable/messages" //here messages is my image name, please give here your image name.
android:bottom="15dp"
android:left="15dp"
android:right="15dp"
android:top="15dp"/>
Second make a view .xml file in layout folder and call the above .xml file with this way
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/merchant_circle" /> // here merchant_circle will be your first .xml file name
Here is another most easy way to get a custom shape for your image (Image View). It may be helpful for someone. It's just a single line code.
First you need to add a dependency:
dependencies {
compile 'com.mafstech.libs:mafs-image-shape:1.0.4'
}
And then just write a line of code like this:
Shaper.shape(context,
R.drawable.your_original_image_which_will_be_displayed,
R.drawable.shaped_image_your_original_image_will_get_this_images_shape,
imageView,
height,
weight);