3
StateListDrawable
似乎會忽略應用於它們包含的drawable的濾色器。例如:如何將顏色過濾器應用於StateListDrawable中的特定繪圖?
StateListDrawable sld = new StateListDrawable();
Drawable pressedState = Context.getResources().getDrawable(R.drawable.solid_green);
pressedState.setColorFilter(Color.RED, PorterDuff.Mode.SRC);
sld.addState(new int[] {android.R.attr.state_pressed}, pressedState);
// Other states...
如果你申請sld
到視圖的背景,你會期望被按下時,視圖的背景變成紅色。相反,它會變成綠色 - 沒有應用濾鏡的pressedState
的顏色。