How to make a round button?

后端 未结 17 2167
夕颜
夕颜 2020-11-28 18:17

I\'m trying to make a round button, but I don\'t know how can I do it. I can make button with rounded corners, but how can I can round circle. It\'s not the same. Please, te

相关标签:
17条回答
  • 2020-11-28 18:50

    If you want a FAB looking circular button and you are using the official Material Component library you can easily do it like this:

    <com.google.android.material.button.MaterialButton
        style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
        app:cornerRadius="28dp"
        android:layout_width="56dp"
        android:layout_height="56dp"
        android:text="1" />
    

    Result:

    If you change the size of the button, just be careful to use half of the button size as app:cornerRadius.

    0 讨论(0)
  • 2020-11-28 18:50

    Yes it's possible, look for 9-patch on google. Good articles :

    http://radleymarx.com/blog/simple-guide-to-9-patch/

    http://ogrelab.ikratko.com/custom-color-buttons-for-android/

    0 讨论(0)
  • 2020-11-28 18:53

    <corners android:bottomRightRadius="180dip"
        android:bottomLeftRadius="180dip"
        android:topRightRadius="180dip"
        android:topLeftRadius="180dip"/>
    
    <solid android:color="#6E6E6E"/> <!-- this one is ths color of the Rounded Button -->
    

    and add this to the button code

        android:layout_width="50dp"
        android:layout_height="50dp"
    
    0 讨论(0)
  • 2020-11-28 18:54

    You can use a MaterialButton:

         <com.google.android.material.button.MaterialButton
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:insetTop="0dp"
                android:insetBottom="0dp"
                android:text="A"
                app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.App.Rounded"
                />
    

    and apply a circular ShapeAppearanceOverlay with:

    <style name="ShapeAppearanceOverlay.App.rounded" parent="">
        <item name="cornerSize">50%</item>
    </style>
    

    0 讨论(0)
  • 2020-11-28 18:55

    Round button in Android

    You can make a ImageButton with circular background image.

    0 讨论(0)
  • 2020-11-28 18:58

    Used the shape as oval. This makes the button oval

    <item>
        <shape android:shape="oval" >
            <stroke
                android:height="1.0dip"
                android:width="1.0dip"
                android:color="#ffee82ee" />
    
            <solid android:color="#ffee82ee" />
    
            <corners
                android:bottomLeftRadius="12.0dip"
                android:bottomRightRadius="12.0dip"
                android:radius="12.0dip"
                android:topLeftRadius="12.0dip"
                android:topRightRadius="12.0dip" />
        </shape>
    </item>
    

    0 讨论(0)
提交回复
热议问题