2016-12-13 69 views
2

我試圖將默認的FloatingActionButton圖標更改爲add circle圖標。我已經從material.io下載了icon ic_add_circle_white_18dp,並將其添加到andorid項目中的drawable directory。然而,當我嘗試使用它我的活動裏面顯示爲黑色內圖標,圖像Android中的浮動操作按鈕無法正確顯示

enter image description here

但是我想FAB圖標看起來像

enter image description here

我FAB圖標XML是什麼樣子

<android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="@dimen/fab_margin" 
     app:srcCompat="@drawable/ic_add_fab" 
     app:elevation="8dp" 
     app:backgroundTint="@android:color/holo_blue_light" 
     app:rippleColor="@android:color/white"/> 

我已經嘗試設置app:backgroundTint VAL UE但它不影響內部圖標樣式

感謝所有幫助

回答

3

導入剪貼畫從圖像資產對應於添加圖標的工作原理:

步驟:

1. Right Click on res. 
2. Select New->Image Asset 
3. In Icon type, select Action Bar and Tab Icons 
4. Provide a name 
5. Select ClipArt in Asset type and the click on the Clip Art icon. 
6. From the content section select add button 
7. In theme set HOLO_DARK 
6. Click Next and then finish 

enter image description here

enter image description here 爲了使用這個作爲一個圖標,包括以下在你的XML中。請注意,使用圖標作爲源android:src="@drawable/ic_add_fab"用於

<android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="@dimen/fab_margin" 
     android:src="@drawable/ic_add_fab" /> 
2

嘗試下載並使用的圖標名稱爲「增加」,而不是「加圈」的圖像

+0

這也並不apparantly工作。 –

+0

無論如何謝謝你,你的答案幫助我達到了解決方案。查看我的答案以獲得完整的解決方案Upvote尋求幫助:) –

+0

謝謝:) @ShubhamKhatri –

1

代替app:srcCompat=使用app:src=
或使用fab.setImageResource(R.drawable.ic_add);以編程方式設置圖像。

+0

無法正常工作 –

+0

反正謝謝你,你的回答讓我朝着正確的方向前進。查看我的答案以獲得完整的解決方案+1幫助:) –

0

您需要設置scaleType爲它正確地顯示:

android:scaleType="center" 
相關問題