本文翻译自:Android changing Floating Action Button color
Been trying for hours to change Material's Floating Action Button color, but without success. 一直试图改变材质的浮动动作按钮颜色,但没有成功。
<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" />
I have tried to add 我试过补充一下
android:background="@color/mycolor"
or via code 或通过代码
FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.profile_edit_fab);
fab.setBackgroundColor(Color.parseColor("#mycolor"));
or 要么
fab.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#mycolor")));
But none of the above worked. 但以上都没有奏效。 I have also tried the solutions in the "duplicate question" , but none of them works, button remained green and also became a square. 我也在“重复的问题”中尝试了解决方案,但它们都没有工作,按钮保持绿色并且也变成了正方形。
I'd like a detailed answer, thanks. 我想详细解答一下,谢谢。
PS It would be also nice to know how to add ripple effect, couldn't understand that eithe