Tint selectableItemBackground with accent color for versions below 21
This commit is contained in:
parent
f2e25cb261
commit
fd57663b86
@ -20,10 +20,10 @@ import android.animation.Keyframe;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.PropertyValuesHolder;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.RippleDrawable;
|
||||
import android.os.Build;
|
||||
@ -247,16 +247,24 @@ public class Utils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color on the {@code view}'s RippleDrawable background,
|
||||
* if its background was set to {@code android.R.attr.selectableItemBackground} or
|
||||
* {@code android.R.attr.selectableItemBackgroundBorderless}.
|
||||
* Sets the color on the {@code view}'s {@code selectableItemBackground} or the
|
||||
* borderless variant, whichever was set as the background.
|
||||
* @param view the view that should have its highlight color changed
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public static void setColorControlHighlight(@NonNull View view, @ColorInt int color) {
|
||||
Drawable selectableItemBackground = view.getBackground();
|
||||
if (selectableItemBackground instanceof RippleDrawable) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
|
||||
&& selectableItemBackground instanceof RippleDrawable) {
|
||||
((RippleDrawable) selectableItemBackground).setColor(ColorStateList.valueOf(color));
|
||||
} else {
|
||||
// Draws the color (src) onto the background (dest) *in the same plane*.
|
||||
// That means the color is not overlapping (i.e. on a higher z-plane, covering)
|
||||
// the background. That would be done with SRC_OVER.
|
||||
// The DrawableCompat tinting APIs *could* be a viable alternative, if you
|
||||
// call setTintMode(). Previous attempts using those APIs failed without
|
||||
// the tint mode. However, those APIs have the overhead of mutating and wrapping
|
||||
// the drawable.
|
||||
selectableItemBackground.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6,4 +6,15 @@
|
||||
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
</style>
|
||||
|
||||
<style name="GridLayoutNumpadElement">
|
||||
<!-- http://stackoverflow.com/a/6868308/5055032
|
||||
Leave off the namespace to reference a custom attribute.
|
||||
Here, we are referencing the "grid:" namespace -->
|
||||
<item name="layout_columnWeight">1</item>
|
||||
<!--<item name="layout_rowWeight">1</item>-->
|
||||
<item name="android:layout_height">@dimen/numeric_keypad_cell_height</item>
|
||||
<item name="android:background">?android:attr/selectableItemBackgroundBorderless</item>
|
||||
<item name="android:gravity">center</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
||||
@ -37,7 +37,7 @@
|
||||
<item name="layout_columnWeight">1</item>
|
||||
<!--<item name="layout_rowWeight">1</item>-->
|
||||
<item name="android:layout_height">@dimen/numeric_keypad_cell_height</item>
|
||||
<item name="android:background">?android:attr/selectableItemBackgroundBorderless</item>
|
||||
<item name="android:background">?android:attr/selectableItemBackground</item>
|
||||
<item name="android:gravity">center</item>
|
||||
</style>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user