-1
我正在製作一個綁定適配器,我可以將濾鏡設置爲drawable。在android.widget.TextView上無法找到屬性'android:drawable'的參數類型爲android.graphics.drawable.Drawable的setter
所以我有這行代碼在java類
@BindingAdapter(value = {"drawable", "filterColor"}, requireAll= true)
public static void setColorFilterToDrawable(View view, int drawableInt, @ColorRes int color){
Drawable drawable = ContextCompat.getDrawable(view.getContext(),drawableInt);
drawable.setColorFilter(new
PorterDuffColorFilter(ContextCompat.getColor(view.getContext(), color), PorterDuff.Mode.SRC_IN));
view.setBackground(drawable);
}
在XML中,我使用這樣的
<TextView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="@+id/textCircle"
android:drawable="@{@drawable/background_circle}"
app:colorFilter="@{@color/primaryDark}"
android:gravity="center"
android:layout_alignParentRight="true"
android:textColor="@android:color/white"
android:textSize="14sp"
android:text="X"
android:textStyle="bold"
android:layout_marginRight="5dp"
android:onClick="@{viewModel::deletePhoto}" />
「TextView」沒有'android:drawable'屬性。這就是爲什麼沒有二傳手。你在試圖使用該drawable來做什麼? –
即時將一個圓形繪製在它 – devadnqpnd
好吧,它應該顯示在哪裏? –