Circle button css
For div
tag there is already default property display:block
given by browser. For anchor tag there is not display property given by browser. You need to add display property to it. That's why use display:block
or display:inline-block
. It will work.
.btn { display:block; height: 300px; width: 300px; border-radius: 50%; border: 1px solid red; }
<a class="btn" href="#"><i class="ion-ios-arrow-down"></i></a>
How to make a round button?
Create an xml file named roundedbutton.xml
in drawable folder
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#eeffffff" />
<corners android:bottomRightRadius="8dp"
android:bottomLeftRadius="8dp"
android:topRightRadius="8dp"
android:topLeftRadius="8dp"/>
</shape>
Finally set that as background to your Button
as android:background = "@drawable/roundedbutton"
If you want to make it completely rounded, alter the radius and settle for something that is ok for you.
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
)
]
)
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" />
How to make a simple rounded button in Storyboard?
To do it in the storyboard, you need to use an image for the button.
Alternatively you can do it in code:
btn.layer.cornerRadius = 10
btn.clipsToBounds = true
Flutter: How to create round/circular button
We can create a circular button by FloatingActionButton
widget.
return Container(
alignment: Alignment.center,
child: new SizedBox(
child: FloatingActionButton(
backgroundColor: Colors.red,
child: null,
onPressed: () {
print("Cliked");
},)
));
}
Output:
Rounded button with Icon flutter
Try this it will work fortextButton
SizedBox(
height: 50,
width: 50,
child: TextButton(
style: TextButton.styleFrom(
backgroundColor: Color(0xffCAEC93),
side: BorderSide(
color: Color(0xffCAEC93),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50),
side: BorderSide(color: Colors.red)),
),
onPressed: () {},
child: Icon(
Icons.add,
color: Colors.white,
)),
),
Or you can try FloatingActionButton
Related Topics
Disable the Touch Events for All the Views
How to Change Background Color Popup Menu Android
How to Finish an Android Application
How to Get Free and Total Size of Each Storagevolume
How to Do Page Flip/Turn/Curl Effect in Android
Load Large Images with Picasso and Custom Transform Object
How to Pop Fragment Off Backstack
Android Listview Setselection() Does Not Seem to Work
Android Studio: Unable to Start the Daemon Process
How to Tell Which App Was Selected by Intent.Createchooser
Start a Fragment via Intent Within a Fragment
Render Error in Android Studio 3.0 Layout Editor
How to Use Startactivityforresult() for Email Intent
Show Toast Widget Underneath a View
Java.Lang.Numberformatexception: Invalid Int: "" in Android
How to Show Dialog in Oncreate Method