自定义Android按钮图像周围的红色圆圈
我创建了一个浮动动作按钮,并制作了自己的图像(每种dpi大小),但周围有一个红色圆圈(下图)。下面是定义按钮的xml自定义Android按钮图像周围的红色圆圈,android,xml,image,android-layout,android-studio,Android,Xml,Image,Android Layout,Android Studio,我创建了一个浮动动作按钮,并制作了自己的图像(每种dpi大小),但周围有一个红色圆圈(下图)。下面是定义按钮的xml <android.support.design.widget.FloatingActionButton android:id="@+id/addplant" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end|bottom"
<android.support.design.widget.FloatingActionButton
android:id="@+id/addplant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
android:src="@mipmap/add_plant"/>
编辑2
无需使用app:backgroundTint
juse在floatingAction按钮中使用android:scaleType=“center”
,它将起作用
<android.support.design.widget.FloatingActionButton
android:id="@+id/addplant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
android:scaleType="center"
android:src="@mipmap/add_plant" />
编辑2
无需使用app:backgroundTint
juse在floatingAction按钮中使用android:scaleType=“center”
,它将起作用
<android.support.design.widget.FloatingActionButton
android:id="@+id/addplant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
android:scaleType="center"
android:src="@mipmap/add_plant" />
用这个
app:useCompatding=“true”
用这个
app:useCompatding=“true”
尝试使用XML属性app:backgroundTint
<android.support.design.widget.FloatingActionButton
android:id="@+id/addplant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
app:backgroundTint="@color/orange" // -----> your background color
android:src="@mipmap/add_plant" />
您的背景色
android:src=“@mipmap/add_plant”/
尝试使用XML属性app:backgroundTint
<android.support.design.widget.FloatingActionButton
android:id="@+id/addplant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
app:backgroundTint="@color/orange" // -----> your background color
android:src="@mipmap/add_plant" />
您的背景色
android:src=“@mipmap/add_plant”/
您可以尝试以下方法-
<android.support.design.widget.FloatingActionButton
...
...
android:src="@drawable/icon" // change backgroung icon
app:backgroundTint="@android:color/transparent" // change background color
/>
将“淡色”设置为“透明”将覆盖您在样式中提供的原色粉红色。您可以尝试以下方法-
<android.support.design.widget.FloatingActionButton
...
...
android:src="@drawable/icon" // change backgroung icon
app:backgroundTint="@android:color/transparent" // change background color
/>
将“淡色”设置为“透明”将覆盖样式中给定的原色粉色。只需使用+符号作为源即可。您不需要传递整个绿色背景的图像。要设置绿色背景色,请使用app:backgroundTint=“@color/green”
像这样更改代码,并使用绿色作为背景色和加号图标作为源代码:
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:backgroundTint="@color/green"
android:src="@drawable/ic_plus" />
仅使用+符号作为源代码。您不需要传递整个绿色背景的图像。要设置绿色背景色,请使用app:backgroundTint=“@color/green”
像这样更改代码,并使用绿色作为背景色和加号图标作为源代码:
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:backgroundTint="@color/green"
android:src="@drawable/ic_plus" />
您可以使用背景色
应用程序:backgroundTint=“@color/green”
从图像中删除背景色,使用无背景图像
您可以使用背景色
应用程序:backgroundTint=“@color/green”
从图像中删除背景色,使用无背景图像
因为浮动操作按钮是由您的。可以将背景色调设置为绿色。我已经更新了你的代码
<android.support.design.widget.FloatingActionButton
android:id="@+id/addplant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
android:backgroundTint="#4CAF50"
android:src="@mipmap/add_plant"/>
因为浮动操作按钮是由您的。可以将背景色调设置为绿色。我已经更新了你的代码
<android.support.design.widget.FloatingActionButton
android:id="@+id/addplant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
android:backgroundTint="#4CAF50"
android:src="@mipmap/add_plant"/>
这不起作用,它只是扩展了按钮的边框。这不起作用,它只是扩展了按钮的边框。你建议使用矢量图形而不是可绘制图形?谢谢,你已经修复了它。看起来很棒!:)你是建议使用矢量图形而不是可绘制图形?谢谢,你已经修复了它。看起来很棒!:)