How to make the corners of a button round?
If you want something like this
here is the code.
1.Create a xml file in your drawable folder like mybutton.xml and paste the following markup:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" >
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<stroke android:width="1dip" android:color="#5e7974" />
<gradient android:angle="-90" android:startColor="#345953" android:endColor="#689a92" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<stroke android:width="1dip" android:color="#5e7974" />
<solid android:color="#58857e"/>
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<stroke android:width="1dip" android:color="#5e7974" />
<gradient android:angle="-90" android:startColor="#8dbab3" android:endColor="#58857e" />
</shape>
</item>
</selector>
2.Now use this drawable for the background of your view. If the view is button then something like this:
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:textColor="#ffffff"
android:background="@drawable/mybutton"
android:text="Buttons" />
Can`t round the corners of the button
Alright, I tested on my Studio with my launcher icon as the image inside and I got the required result. Here's the entire xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="@+id/bottle"
android:layout_width="100dp"
android:layout_height="100dp"
android:contentDescription="@null"
app:srcCompat="@mipmap/ic_launcher"
android:background="@drawable/rouncorners"/>
</android.support.constraint.ConstraintLayout>
And the xml to be placed in the drawable file is:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="3dip" android:color="@color/profile_cover" />
<corners android:radius="10dp" />
</shape>
The result was as follows:
This is what you're looking for right? It have rounded corner and an image inside.
How to round the corners of a button
I tried the following solution with the UITextArea and I expect this will work with UIButton as well.
First of all import this in your .m file -
#import <QuartzCore/QuartzCore.h>
and then in your loadView
method add following lines
yourButton.layer.cornerRadius = 10; // this value vary as per your desire
yourButton.clipsToBounds = YES;
Button with rounded corners and border with color
This one is what you need.
public static void setRoundedDrawable(Context context, View view, int backgroundColor, int borderColor) {
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.RECTANGLE);
shape.setCornerRadius(20f);
shape.setColor(backgroundColor);
if (borderColor != 0){
shape.setStroke(2f, borderColor);
}
view.setBackgroundDrawable(shape);
}
You can change corner radius and stroke width depends on what you need.
Hope it helps!
Rounded corners on material button
Update:
Answer by Gabriele Mariotti below is now better.
Old answer:
You need to inherit that style.
Add into your styles.xml:
<style name="AppTheme.RoundedCornerMaterialButton" parent="Widget.AppCompat.Button.Colored">
<item name="android:background">@drawable/rounded_shape</item>
</style>
Add file drawable/rounded_shape.xml:
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid
android:color="@color/colorAccent" >
</solid>
<corners
android:radius="11dp" >
</corners>
</shape>
And finally in your layout:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test Text"
style="@style/AppTheme.RoundedCornerMaterialButton"/>
Edit: updated answer to use theme's color rather than hardcoded one.
Create a rounded button / button with border-radius in Flutter
1. Solution Summary
FlatButton
and RaisedButton
are deprecated.
So, you can use shape
which placed in the style
property, for TextButton
and ElevatedButton
.
There are some changes since Flutter 2.0:
style
: the property type has changed toButtonStyle
shape
: the property type has changed toMaterialStateProperty<T>
2. Rounded Button
Inside the style
property exists the shape
property:
style: ButtonStyle(
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
side: BorderSide(color: Colors.red)
)
)
)
Square Button
For a square button you can use ElevatedButton
or otherwise add:
style: ButtonStyle(
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
side: BorderSide(color: Colors.red)
)
)
)
Complete Example
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
child: Text(
"Add to cart".toUpperCase(),
style: TextStyle(fontSize: 14)
),
style: ButtonStyle(
padding: MaterialStateProperty.all<EdgeInsets>(EdgeInsets.all(15)),
foregroundColor: MaterialStateProperty.all<Color>(Colors.red),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
side: BorderSide(color: Colors.red)
)
)
),
onPressed: () => null
),
SizedBox(width: 10),
ElevatedButton(
child: Text(
"Buy now".toUpperCase(),
style: TextStyle(fontSize: 14)
),
style: ButtonStyle(
foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
backgroundColor: MaterialStateProperty.all<Color>(Colors.red),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
side: BorderSide(color: Colors.red)
)
)
),
onPressed: () => null
)
]
)
Googles new buttons - how to do rounded ends in CSS
I think you're in the right track, just set it as larger as it makes you safe thinking about maximum height of button/item/div/whatever. I've checked Google Drive button by inspecting it, its border-radius is set to be 66px.
Notice that I've set the 4 corners in the same border-radius property, 2 of them being 0 just like the example. The border-radius are defined in the following order: top-left, top-right, bottom-right, bottom-left.
.button { padding: 10px 30px; background: red; border: none; border-radius: 0 100px 100px 0;}
<button class="button">Hello world</button>
How to add rounded corners to a single side in HTML-CSS]
Try like following snippet, for more info take a look here:
.button {
border: 1px solid #00bfff;
border-bottom-right-radius: 30%;
border-top-right-radius: 30%;
padding: 20px;
background: #00bfff;
}
<button type="button" class="button">Button</button>
Xamarin iOS Round only some corners of a Button
You can use MaskedCorners in your iOS class to control the display of graphics.
Here is my implementation class for your reference:
[assembly: ExportRenderer(typeof(CustomButton),typeof(CurvedCornersButtonRenderer))]
namespace xxx.iOS
{
class CurvedCornersButtonRenderer : ButtonRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
Control.BackgroundColor = UIColor.Blue;
Control.ClipsToBounds = true;
Control.Layer.CornerRadius = 15;
Control.Layer.MaskedCorners = CoreAnimation.CACornerMask.MaxXMinYCorner | CoreAnimation.CACornerMask.MaxXMaxYCorner;
}
}
}
Related Topics
What Is the Meaning of This Declaration
Where Should I Be Setting Autolayout Constraints When Creating Views Programmatically
Differencebetween the App Id and the Bundle Id? Where Is the App Id in the Xcode Project
Using iOS Gamekit's "Bluetooth Bonjour" with Other Platforms
How Does Uiedgeinsetsmake Work
How to Open Location Services Screen from Setting Screen
New React Native Project with Old Version of React Native
Detect If a Point Is Inside a Mkpolygon Overlay
Generics in Swift - "Generic Parameter 'T' Could Not Be Inferred
How to Remove All Gesture Recognizers from a Uiview in Swift
iOS Documents Directory Size Limit
Convert Existing iOS Paid App to Freemium Model with In-App Purchase
Swift - Segmented Control - Switch Multiple Views
Cannot Install Cocoapods - No Podfile Found in the Project Directory