我一直在尝试更改材料的浮动操作按钮颜色,但没有成功。
<android.support.design.widget.FloatingActionButton
android:id="@+id/profile_edit_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="16dp"
android:clickable="true"
android:src="@drawable/ic_mode_edit_white_24dp" />
我试图补充说:
android:background="@color/mycolor"
或者通过代码:
FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.profile_edit_fab);
fab.setBackgroundColor(Color.parseColor("#mycolor"));
或
fab.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#mycolor")));
但上述方法都没有奏效。我还尝试了提出的重复问题中的解决方案,但都不起作用;按钮仍然是绿色的,也变成了一个正方形。
另外,如果知道如何添加涟漪效果也会很好,我也不能理解。
发布于 2015-09-16 22:07:10
如果您尝试使用应用程序更改FAB的颜色,会出现一些问题。按钮的边框有不同的颜色,所以你必须做的是:
app:backgroundTint="@android:color/transparent"
并在代码中设置颜色:
actionButton.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.white)));
发布于 2016-03-08 17:00:38
只需使用
app:backgroundTint="@color/colorPrimary"
不要使用,
android:backgroundTint="@color/colorPrimary"
发布于 2015-06-22 05:55:41
FAB根据您的colorAccent
进行着色。
<style name="AppTheme" parent="Base.Theme.AppCompat.Light">
<item name="colorAccent">@color/accent</item>
</style>
https://stackoverflow.com/questions/30969455
复制相似问题