2015-06-17 129 views
2

我找不到一個沒有邊框的FAB。例如,當我嘗試:FloatingActionButton無邊框?

<android.support.design.widget.FloatingActionButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/fab" 
    android:background="@android:color/transparent" 
    android.support.design:fabSize="normal" 
    android:adjustViewBounds="true" 
    style="@style/Fab"/> 

我得到:

Screenshot

通知邊框仍然圍繞FAB。我已經嘗試adjustViewBounds =「true」和android:background =「@ android:color/transparent」這兩個都是建議的解決方案,用於擺脫ImageView(FAB擴展)上的邊框,但都不起作用。我怎樣才能擺脫這個邊界?

注意:all @ style/Fab確實是定位按鈕,與邊框無關。

+0

也試過android:scaleType =「fitXY」,結果相同 –

+1

你爲什麼要試圖建立一個透明的FAB? – ianhanniballake

+1

嘗試將borderwidth設置爲0dp..app:borderWidth =「0dp」 – Psypher

回答

5

只是在你的佈局文件添加app:borderWidth="0dp"

<android.support.design.widget.FloatingActionButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/fab" 
    app:borderWidth="0dp" 
    android:background="@android:color/transparent" 
    android.support.design:fabSize="normal" 
    android:adjustViewBounds="true" 
    style="@style/Fab"/> 

中還添加有加入這一優勢,它修復了API <中的方形FAB問題15.

更新:Android支持的最新更新d oes不需要borderwidth = 0dp來修復方形FAB。

+0

我試圖擺脫我的FAB的背景,並沒有奏效。對於'android:background =「@ android:color/transparent」'這一行沒有任何效果。 – Zvi

+0

我甚至試着改變那條線的顏色,但是我的FAB始終以來自顏色文件'colorPrimary'的相同顏色出現。當我改變顏色時,FAB背景顏色會改變。 – Zvi

0

原來這是

app:borderWidth="0dp" 

是我的錯。謝謝@Ranjith。

這在某種程度上也增加了一個陰影下的按鈕:

enter image description here

+1

雖然你的圖標是錯誤的大小。該圖標應該是24dp。請參閱https://github.com/google/material-design-icons/blob/master/content/drawable-hdpi/ic_send_white_24dp.png(也提供xhdpi,xxhdpi ...版本)和奇怪的居中 – njzk2

+0

我知道,這個應用程序僅用於測試。謝謝你。 –