mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +08:00
Merge pull request #3683 from NativeScript/seg-bar-highligh-fix
Fix: Setting slected color on SegmentedBar affects all seg-bars
This commit is contained in:
@ -110,19 +110,21 @@ export class SegmentedBarItem extends SegmentedBarItemBase {
|
||||
this._textView.setTypeface(value instanceof Font ? value.getAndroidTypeface() : value);
|
||||
}
|
||||
|
||||
get [selectedBackgroundColorProperty.native](): android.graphics.drawable.Drawable {
|
||||
get [selectedBackgroundColorProperty.native](): android.graphics.drawable.Drawable.ConstantState {
|
||||
let viewGroup = <android.view.ViewGroup>this._textView.getParent();
|
||||
return viewGroup.getBackground();
|
||||
return viewGroup.getBackground().getConstantState();
|
||||
}
|
||||
set [selectedBackgroundColorProperty.native](value: Color | android.graphics.drawable.Drawable) {
|
||||
set [selectedBackgroundColorProperty.native](value: Color | android.graphics.drawable.Drawable.ConstantState) {
|
||||
let viewGroup = <android.view.ViewGroup>this._textView.getParent();
|
||||
if (value instanceof Color) {
|
||||
let color = value.android;
|
||||
let backgroundDrawable = viewGroup.getBackground();
|
||||
const backgroundDrawable = viewGroup.getBackground();
|
||||
if (apiLevel > 21 && backgroundDrawable && typeof backgroundDrawable.setColorFilter === "function") {
|
||||
backgroundDrawable.setColorFilter(color, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||
const newDrawable = backgroundDrawable.getConstantState().newDrawable();
|
||||
newDrawable.setColorFilter(color, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||
setBackground(viewGroup, newDrawable);
|
||||
} else {
|
||||
let stateDrawable = new android.graphics.drawable.StateListDrawable();
|
||||
const stateDrawable = new android.graphics.drawable.StateListDrawable();
|
||||
|
||||
let arr = Array.create("int", 1);
|
||||
arr[0] = R_ATTR_STATE_SELECTED;
|
||||
@ -133,7 +135,7 @@ export class SegmentedBarItem extends SegmentedBarItemBase {
|
||||
setBackground(viewGroup, stateDrawable);
|
||||
}
|
||||
} else {
|
||||
setBackground(viewGroup, value);
|
||||
setBackground(viewGroup, value.newDrawable());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user