无法更改FloatingActionButton的背景和backgroundTint背景颜色,支持设计23.2.0

问题描述:

这是我的代码:无法更改FloatingActionButton的背景和backgroundTint背景颜色,支持设计23.2.0

<android.support.design.widget.FloatingActionButton 
     android:id="@+id/enter_floating_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:layout_marginBottom="40dip" 
     android:layout_marginRight="10dip" 
     android:clickable="true" 
     app:background="#00FF00" 
     app:backgroundTint="#00FF00" 
     app:rippleColor="@android:color/red" 
     app:fabSize="normal" 
     android:src="@drawable/ic_done" /> 

正如你所看到的,我设置app:backgroundapp:backgroundTint,但这些都没有用,FloatingActionButton's背景颜色不会改变,并且或者app:rippleColor,当我按下它的颜色不是我设置的按钮,看起来像主题中的accentColor。

为什么这些属性不起作用?

如何更改FloatingActionButton's背景和波纹颜色?

我曾看过这个:Android changing Floating Action Button color。有些答案可能在22工作,但我并没有在23

找到一个有用的方法浮动操作按钮将颜色从服用属性colorAccent中的颜色styles.xml.Set的风格,并设置样式这个浮动操作按钮,然后它会工作

+0

这可能是有用的,但机器人:colorAccent需要API等级21,我的API级别是14 –

+0

尝试像这样使用一些颜色而不在st中使用android命名空间你正在使用的yle。 – srinivas

+0

我曾试过这个,不行。也许,我用23 –

尝试在你的FloatingActionButton类添加编程纹波颜色:

 public RippleView(Context context, AttributeSet attrs, int defStyle) { 
       super(context, attrs, defStyle); 
       mContext = context; 
       init(); 
       TypedArray a = context.obtainStyledAttributes(attrs, 
         R.styleable.RippleView); 
       mRippleColor = a.getColor(R.styleable.RippleView_rippleColor, 
         mRippleColor); 
       mAlphaFactor = a.getFloat(R.styleable.RippleView_alphaFactor, 
         mAlphaFactor); 
       mHover = a.getBoolean(R.styleable.RippleView_hover, mHover); 
       a.recycle(); 
      } 


    public void init() { 
      mDensity = getContext().getResources().getDisplayMetrics().density; 

      mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 
      mPaint.setAlpha(20); 
      setRippleColor(Color.BLACK, 0.2f); 
      // setRippleColor(Color.parseColor(getResources().getColor(R.color.greycolor), 0.2f); 
      // setRippleColor(0x000000, 0.1f); 
     } 

     public void setRippleColor(int rippleColor, float alphaFactor) { 
      mRippleColor = rippleColor; 
      mAlphaFactor = alphaFactor; 
     } 

public void setHover(boolean enabled) { 
     mHover = enabled; 
    }