2

我正在尝试在代码中创建一个按钮选择器 - 并为按下状态添加一个色调。但是,我所做的一切似乎都不会影响 BitmapDrawable。这是我的代码(使用 Xamarin.Android):

    void SetSelector(Button b, Bitmap bitmap)
    {
        StateListDrawable states = new StateListDrawable ();
        BitmapDrawable d1 = new BitmapDrawable (bitmap);
        BitmapDrawable d2 = new BitmapDrawable (bitmap);
        d1.SetColorFilter (global::Android.Graphics.Color.Red, PorterDuff.Mode.Multiply);
        states.AddState (new int[] { global::Android.Resource.Attribute.StatePressed }, d1);
        states.AddState (new int[] { }, d2);
        b.SetBackgroundDrawable (states);
    }

我尝试过不同的东西。创建一个 LightningColorFilter 并将其设置在 BitmapDrawable 或 Paint 对象等上。似乎根本没有任何效果。从根本上说我缺少什么吗?

4

0 回答 0