我想这样做:FloatingActionButton 我想设置一个图像并将颜色更改为:绿色。我尝试这样做:
<com.xxx.test.fab.FloatingActionButton
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ikona2"
android:tint="@color/green"
app:layout_anchor="@id/mapview"
app:layout_anchorGravity="bottom|left|end" />
但是这个浮动ActionButton仍然是红色的
实际上,您可以更改背景颜色:
aBu.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.white)));
在
xml
中你可以使用:
app:backgroundTint="@color/red"
或使用以下代码设置按钮:
aBu.setImageResource(R.drawable.ic_image_name);
尝试
app:backgroundTint
.FloatingActionButton 来自支持库,因此您必须使用 app 命名空间。 android命名空间可能导致崩溃或不正常工作
android
通常用于来自Android SDK本身的属性。
如果您使用支持库,则经常使用app
。
<com.smok.maps.fab.FloatingActionButton
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ikona2"
app:backgroundTint="@color/green"
app:layout_anchor="@id/mapview"
app:layout_anchorGravity="bottom|left|end" />
要设置图像,请尝试:
floatingActionButoon.setImageResource(R.drawable.ic_image_name);
我希望这对你有用。
而不是这个
android:tint="@color/green"
使用
android:backgroundTint="#008000"