[6.3.0][View点击态] 修正由于外部输入设备(蘑方)连接后,界面部分控件展示阴影

This commit is contained in:
renwj
2024-03-08 16:46:45 +08:00
parent 4c3592e526
commit 3e395dd003
4 changed files with 19 additions and 16 deletions

View File

@@ -6,6 +6,7 @@ import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.os.Build;
import android.util.AttributeSet;
import android.util.StateSet;
import android.view.LayoutInflater;
@@ -513,7 +514,7 @@ public class ViewPressedStateLancet {
}
int[][] states = new int[size][1];
int[] colors = new int[size];
states[0] = new int[] { android.R.attr.state_pressed, -android.R.attr.state_focused };
states[0] = new int[] { android.R.attr.state_pressed, -android.R.attr.state_focused, -android.R.attr.state_active };
colors[0] = pressedColor;
if (size > 2) {
states[1] = new int[] { -android.R.attr.state_enabled };
@@ -581,8 +582,19 @@ public class ViewPressedStateLancet {
int[] states = drawable.getState();
boolean hasPressed = false;
for (int state : states) {
if (state == android.R.attr.state_pressed) {
if ((state & android.R.attr.state_pressed) != 0) {
hasPressed = true;
Drawable pressed = null;
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
int index = drawable.findStateDrawableIndex(new int[] { android.R.attr.state_pressed });
pressed = drawable.getStateDrawable(index);
}
} catch (Throwable ignore) {}
if (pressed != null) {
drawable.addState(new int[] { -android.R.attr.state_active, -android.R.attr.state_focused }, pressed);
}
break;
}
}
@@ -594,7 +606,7 @@ public class ViewPressedStateLancet {
if (constantState != null) {
Drawable pressed = DrawableCompat.wrap(constantState.newDrawable().mutate());
pressed.setAlpha((int)(255 * alpha));
drawable.addState(new int[] { android.R.attr.state_pressed }, pressed);
drawable.addState(new int[] { android.R.attr.state_pressed, -android.R.attr.state_focused, -android.R.attr.state_active }, pressed);
return drawable;
}
return null;
@@ -604,7 +616,7 @@ public class ViewPressedStateLancet {
StateListDrawable result = new StateListDrawable();
Drawable pressed = DrawableCompat.wrap(constantState.newDrawable().mutate());
pressed.setAlpha((int)(255 * alpha));
result.addState(new int[] { android.R.attr.state_pressed, -android.R.attr.state_focused }, pressed);
result.addState(new int[] { android.R.attr.state_pressed, -android.R.attr.state_focused, -android.R.attr.state_active }, pressed);
result.addState(StateSet.WILD_CARD, old);
return result;
}