diff --git a/tns-core-modules/ui/segmented-bar/segmented-bar.android.ts b/tns-core-modules/ui/segmented-bar/segmented-bar.android.ts index 410798bc4..728a280e9 100644 --- a/tns-core-modules/ui/segmented-bar/segmented-bar.android.ts +++ b/tns-core-modules/ui/segmented-bar/segmented-bar.android.ts @@ -1,7 +1,7 @@ import { Font } from "../styling/font"; import { SegmentedBarItemBase, SegmentedBarBase, selectedIndexProperty, itemsProperty, selectedBackgroundColorProperty, - colorProperty, fontInternalProperty, fontSizeProperty, Color, initNativeView + colorProperty, fontInternalProperty, fontSizeProperty, Color, initNativeView, layout } from "./segmented-bar-common"; export * from "./segmented-bar-common"; @@ -24,6 +24,7 @@ interface TabHost { } let apiLevel: number; +let selectedIndicatorThickness: number; let TabHost: TabHost; let TabChangeListener: TabChangeListener; @@ -34,6 +35,10 @@ function initializeNativeClasses(): void { return; } + apiLevel = android.os.Build.VERSION.SDK_INT; + // Indicator thickness for material - 2dip. For pre-material - 5dip. + selectedIndicatorThickness = layout.toDevicePixels(apiLevel >= 21 ? 2 : 5); + @Interfaces([android.widget.TabHost.OnTabChangeListener]) class TabChangeListenerImpl extends java.lang.Object implements android.widget.TabHost.OnTabChangeListener { constructor(private owner: SegmentedBar) { @@ -163,10 +168,9 @@ export class SegmentedBarItem extends SegmentedBarItemBase { org.nativescript.widgets.ViewHelper.setBackground(viewGroup, newDrawable); } else { const stateDrawable = new android.graphics.drawable.StateListDrawable(); - + let colorDrawable: android.graphics.drawable.ColorDrawable = new org.nativescript.widgets.SegmentedBarColorDrawable(color, selectedIndicatorThickness); let arr = Array.create("int", 1); arr[0] = R_ATTR_STATE_SELECTED; - let colorDrawable: android.graphics.drawable.ColorDrawable = new org.nativescript.widgets.SegmentedBarColorDrawable(color); stateDrawable.addState(arr, colorDrawable); stateDrawable.setBounds(0, 15, viewGroup.getRight(), viewGroup.getBottom()); diff --git a/tns-platform-declarations/android/org.nativescript.widgets.d.ts b/tns-platform-declarations/android/org.nativescript.widgets.d.ts index 5eb6e759b..45e1a93a8 100644 --- a/tns-platform-declarations/android/org.nativescript.widgets.d.ts +++ b/tns-platform-declarations/android/org.nativescript.widgets.d.ts @@ -498,6 +498,7 @@ } export class SegmentedBarColorDrawable extends android.graphics.drawable.ColorDrawable { + constructor(color: number, thickness: number); } export class CustomTypefaceSpan extends android.text.style.TypefaceSpan {