question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MaterialButton with specific corners rounded

See original GitHub issue

I am trying to make a button with only one side rounded (left or right). screenshot at 2018-06-07 18_47_53

Since the attribute app:cornerRadius is applied to all four corners of the button, I’ve tried to set the background:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@color/white" />
    <corners
        android:bottomLeftRadius="30dp"
        android:topLeftRadius="30dp" />
</shape>
<android.support.design.button.MaterialButton
        style="@style/Widget.MaterialComponents.Button"
        android:background="@drawable/my_background"/>

But it didn’t work, because I suppose setting a custom background is not supported for it.

Any ideas how to reach only one rounded side for MaterialButton?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:14
  • Comments:5

github_iconTop GitHub Comments

25reactions
AndroidDeveloperLBcommented, Oct 31, 2019

@tommybuonomo Pretty sure it’s supposed to be in pixels. Also, when I choose it this way, it becomes black and without any effect when clicking. How can I set it to just have this shape for the button, yet keep the color and the clicking effect ? I’ve also noticed that it’s deprecated and that we should use ShapeAppearanceModel instead: https://developer.android.com/reference/com/google/android/material/shape/ShapePathModel

So I think the correct way to do something like that could be like:

https://blog.octo.com/en/android-materialshapedrawable/

Example:

        <com.google.android.material.button.MaterialButton
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="asd"
            app:backgroundTint="@color/colorPrimary"
            app:shapeAppearance="@style/CustomShapeAppearance" />

    <style name="CustomShapeAppearance">
        <item name="cornerSizeTopLeft">16dp</item>
        <item name="cornerSizeTopRight">16dp</item>
    </style>
15reactions
tommybuonomocommented, Jun 7, 2018

Hi @TanyaYu, You can achieve this working with MaterialShapeDrawable. You’ll be able to set custom corners treatments to the MaterialShapeDrawable, and apply it to your button.

For example:

    val leftShapePathModel = ShapePathModel()
    leftShapePathModel.topLeftCorner = RoundedCornerTreatment(/*radius corner in dp*/)
    leftShapePathModel.bottomRightCorner= RoundedCornerTreatment(/*radius corner in dp*/)
    val leftRoundedMaterialShape = MaterialShapeDrawable(leftShapePathModel)
    button.setBackgroundDrawable(leftRoundedMaterialShape)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Rounded corners on material button - android - Stack Overflow
Use app:cornerRadius attribute to change the size of corner radius. This will round off the corners with specified dimensions. enter image description here....
Read more >
Rounded Button in Android Studio - The Startup - Medium
Now , in the main xml file where you want the rounded corners for the button , add this line : android:background=”@drawable/rounded_corner ”...
Read more >
rounded corner material button android Code Example
Answers related to “rounded corner material button android” ... Your Ruby version is 3.0.0, but your Gemfile specified 2.7.4 · Your Ruby version...
Read more >
How to Android button rounded corners | Radius, ripple ...
To create an Android button rounded corners have to use a new XML file. This new XML file will be inside a drawable...
Read more >
Shape theming - Material Design
Currently shape system for web only supports rounded corners. ... Styles for applying shapes for specific corners such as drawer looks like this:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found