Android 如何创建中心包含图标的小圆形按钮?
我想在我的android应用程序中创建按钮,如下图所示 您可以使用下面的四个按钮 我想给他们一个自定义的颜色背景,然后在顶部的图标。我无法调整按钮中心的图标Android 如何创建中心包含图标的小圆形按钮?,android,Android,我想在我的android应用程序中创建按钮,如下图所示 您可以使用下面的四个按钮 我想给他们一个自定义的颜色背景,然后在顶部的图标。我无法调整按钮中心的图标 如何实现所需效果?创建可绘制并将其用作按钮背景 <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item> <sh
如何实现所需效果?创建可绘制并将其用作按钮背景
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<stroke android:color="#e1e1e1"
android:width="0.5dp"/>
<solid android:color="@android:color/white"/>
</shape>
</item>
</selector>
这段代码创建了一个白色背景的圆。您可以使用FrameLayout来实现这一点,对于圆形背景,您需要创建一个可绘制形状的文件。请参考我的答案
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<stroke android:color="#e1e1e1"
android:width="0.5dp"/>
<solid android:color="@android:color/white"/>
</shape>
</item>
</selector>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/round_shape"
android:clickable="true"
android:focusable="true"
android:visibility="visible"
android:foreground="?android:attr/selectableItemBackground"
android:padding="4dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_star_border_black_24dp"/>
</FrameLayout>
round_shape.xml将此文件添加到可绘制文件夹中
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<gradient
android:angle="270"
android:startColor="@color/profile_grey"
android:endColor="@color/profile_grey"/>
</shape>
这里是按钮的最佳库-Android库就足够了。刚刚读“ToMasasMali,我知道如何创建圆形按钮,但我不能把一个图标在按钮的中心有一个彩色的背景。”但是,把一个图标放在这个背景的顶部,中间也是另一个故事。@ YaTunDrRaSARORE,检查我的答案,它可以帮助你<代码> <代码>试试这个。使用图像视图而不是按钮。