How to create a cutom rectangle shape in android [on hold] - android

I want to create an edit text of rectangle shape with one side is curved to inside, like what I have shown in the figure
I have tried this, but it curves just the corners.
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#color/mep_blue"></solid>
<!--<stroke android:color="f00"-->
<!--android:width="0"></stroke>-->
<stroke android:color="#a49b9b"
android:width="0.10dp"/>
<corners
android:topLeftRadius="-100dp"
android:topRightRadius="-100dp"
android:bottomLeftRadius="100dp"
android:bottomRightRadius="100dp"
/> </shape

Related

How I can do a button with left/right side as rounded as circle

I'm trying to do a button with the sides rounded, but when I change the size of screen the button sides left to be rounded as circles, doesn't mantain the aspect ratio (I think).
I want to have the next togglebutton in everysize. How I can do an XML with the sides rounded for every resolution?
I've read this, but is not a solution (How to make the corners of a button round?)
Create a drawable resource file in xml. The following is code for a blue button
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#2196f3"></solid>
<corners android:radius="12dp"></corners>
</shape>
Then just asign this resource file as the background to one of your textViews
I hope this helps
The other answers are correct... almost:
if you will set corners to some value (let's say 20dp), but your button height will be greater (like 40dp) - you will end with rounded corners instead of rounded sides. The solution is thus straightforward: set android:corners attribute to some high enough value that will be greater than button height:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#color/colorPrimary" />
<corners android:radius="200dp" />
<size
android:height="16dp"
android:width="32dp" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="20dp" />
<solid android:color="#1ee" />
</shape>

Creating android shape that keeps proportions

How do I create an XML ressource shape that looks like a perfect circle no matter which object it is applied to? When I try to add it as a background to a button, it becomes a oval in stead of a circle.
try this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="ring" android:innerRadiusRatio="5"
android:visible="true" android:thickness="4dp"
>
<stroke android:color="#654321"
android:width="2dp"/>
<solid android:color="#123456"/>
</shape>

How to make android round buttons

I have tried to search this a lot however I was not able to make the same buttons as in the picture for android.
I have been trying to use the following code but the button is not transparent and it doesn't have that nice rounding on the sides:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#ffffff" />
<corners android:radius="15dp" />
</shape>
Currently it looks like this
I want the EditTexts and the buttons to be transparent with a white border
It would be a great great help if someone could assist me on this.
Defining shape is proper approach. If you want it to be transparent with white border you need to avoid using solid tag and use stroke (that is the border).
So for example you will have this shape (let's call it bg_button.xml under drawable folder):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:color="#android:color/white" android:width="1dp" />
<corners android:radius="15dp" />
</shape>
Apply then this to your views as background. This is an example:
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Facebook"
android:background="#drawable/bg_button"/>
Please try this not just on Android Studio editor but also on your emulator / device. Rendering of rounded corners on Android Studio editor can create problems.
Currently it looks like this
I want the EditTexts and the buttons to be transparent with a white border
By using the following code:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="35dp" />
<stroke android:color="#android:color/white" android:width="1dp" />
<!--<solid android:color="#ffffff" />-->
</shape>
I get the following problem:
As you can see on the sides there is area greyed out....

android button with half circle edges

I am trying to create a shape to be used for my imagebuttons in my android project that would essentially have half circles for the left and right sides.
i thought i could just use a shape XML with a radius. but that just rounds the corners where i need the whole left and right sides to be half circles like the image below.
my current xml for the shape looks like this:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:color="#color/white">
<corners
android:radius="60dip"
/>
<stroke
android:width="0dp"
android:color="#000000" />
<solid
android:color="#color/white" />
</shape>
but i am trying to get this effect :
How tall is your button? The shape drawable with rounded corners should work, you want the radius to be half of the height of the button.
You must specify every corner radius like this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#color/green" />
<size android:height="30dp" />
<corners
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topRightRadius="15dp"
android:topLeftRadius="15dp"
/>
</shape>
You should not specify the width, so that it can adjust the width as background drawable.

Shape corners with negative radius in Android

I want to create a composite view with corners that looks like this:
How it this possible in Android?
If someone have the same problem, best way is use 9.png drawables. In xml it's not possible.
You can able to give the OneSide Corner with set the below frame as background to the layout.
<?xml version="1.0" encoding="UTF-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dip"
/>
<solid
android:color="#3D2A1D"/>
<corners
android:radius="20sp"
android:topRightRadius="0dp"
android:bottomLeftRadius="0dp"
android:bottomRightRadius="0dp"/>
</shape>
I am not sure with the -ve border radios.

Resources