2015-07-03 57 views
5

当我设置的色彩我的工厂,它看起来像这样:浮动操作按钮作为一个正方形

enter image description here

我的布局XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" 
tools:context=".MainActivity$PlaceholderFragment"> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/ic_add" 
    android:layout_marginRight="20dp" 
    app:fabSize="normal" 
    android:elevation="@dimen/fab_elevation" 
    android:background="#000000" 
    android:stateListAnimator="@animator/fab_anim" 
    android:layout_gravity="center_horizontal" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentEnd="true" /> 

而且颜色不会改变。 任何人都可以帮助我理解我做错了什么吗?

我也尝试了一个@color链接,但它坠毁,背景为可绘制的(ex. android:background="@drawable/fab_background")没有任何反应。

这里是可拉伸fab_background.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

<item> 
    <ripple android:color="@color/fab_color_1_muted"> 
     <item> 
      <shape> 
       <solid android:color="@color/fab_color_1" /> 
      </shape> 
     </item> 
    </ripple> 
</item> 

+0

将'app:borderWidth =“0dp”'添加到布局。 – Ziem

+0

[FAB - 前棒棒糖上的正方形和棒棒糖上没有影子]的可能重复(http://stackoverflow.com/questions/30538604/fab-square-on-pre-lollipop-and-without-shadow-on-lollipop) – Ziem

+0

它解决了吗?或者你期待的行为是什么? – srinivasan

回答

4

使用

app:backgroundTint="@android:color/holo_green_dark" 

(例如)来设置的晶圆厂颜色。以下结果。 Taken from this -tested- code snippet.

enter image description here

还可以编辑: “奇怪的绿色” 应该来自你的口音的颜色。这是颜色厂默认采用的。

+0

使用链接的代码对我很有用。谢谢! 绿色是超级酷。 – SMKS

5

使用此代码在XML

应用:边框宽度= “0dp”

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/ic_add" 
    android:layout_marginRight="20dp" 
    app:fabSize="normal" 
    android:elevation="@dimen/fab_elevation" 
    android:background="#000000" 
    app:borderWidth="0dp" 
    android:stateListAnimator="@animator/fab_anim" 
    android:layout_gravity="center_horizontal" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentEnd="true" /> 
+1

v22.2.1中已修复此问题,无需再执行此操作。 –

0

只需添加app:borderWidth="0dp"

0

简单的设置应用程序:边框宽度= “0dp” 解决问题。