2015-07-03 52 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」 解決問題。