我想为我的应用程序提供一个圆形按钮颜色选择器,如下所示。
我尝试过的是这个。创建如此多具有不同背景颜色的圆形按钮。看起来效率有点低。单击该按钮将选择颜色。有一个更好的方法吗 ?
//rounded.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#ff0000" />
<corners android:bottomRightRadius="35dp"
android:bottomLeftRadius="35dp"
android:topRightRadius="35dp"
android:topLeftRadius="35dp"/>
</shape>
//In Layout
<Button
android:id="@+id/button2"
android:layout_width="70dp"
android:layout_height="70dp"
android:background="@drawable/roundedbutton"
android:text="Button" />
最佳答案
你可以使用 FloatingActionButton
A floating action button (FAB) is a circular button that triggers the primary action in your app's UI
Floating action buttons are used for a special type of promoted action. They are distinguished by a circled icon floating above the UI and have special motion behaviors related to morphing, launching, and the transferring anchor point.
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:src="@drawable/ic_my_icon"
android:layout_margin="16dp" />
编辑
对于颜色选择器,您可以使用以下库
关于android - Android 中的圆形按钮颜色选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50200698/