[英]Tint attribute not working on floating action button - cannot change the icon colour
我正在嘗試做一些非常簡單的事情,在浮動操作按鈕上設置圖標的色調,但 tint 屬性不會改變它的顏色。
即使更改了圖標的 XML 本身,浮動操作按鈕似乎仍將圖標保持為黑色。
我只想將圖標更改為白色!
晶圓廠 XML:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/createPostBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:backgroundTint="#006993"
android:clickable="true"
android:focusable="true"
android:src="@drawable/ic_textpost"
android:tint="@color/white"
app:layout_constraintBottom_toTopOf="@+id/add_btn"
app:layout_constraintEnd_toEndOf="@+id/add_btn" />
ic_textpost.xml:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="@color/white">
<path
android:fillColor="@android:color/white"
android:pathData="M17,19.22H5V7h7V5H5C3.9,5 3,5.9 3,7v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2v-7h-2V19.22z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M19,2h-2v3h-3c0.01,0.01 0,2 0,2h3v2.99c0.01,0.01 2,0 2,0V7h3V5h-3V2z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M7,9h8v2h-8z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M7,12l0,2l8,0l0,-2l-3,0z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M7,15h8v2h-8z"/>
</vector>
您需要使用app:tint
,而不是android:tint
來設置顏色。
見官方材料文檔。 在此期間,它是相當不錯的。
https://material.io/components/buttons-floating-action-button/android#fabs
@android:color/white to "#fff"
如果您進行更改,它很可能會修復。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.