Use setBackgroundDrawable for API < 16. (#3108)

This commit is contained in:
vB Results, LLC
2016-11-18 20:47:06 +08:00
committed by Vladimir Enchev
parent c669fa8281
commit 978bd8c524
2 changed files with 28 additions and 5 deletions

View File

@@ -290,7 +290,11 @@ export class SegmentedBarStyler implements style.Styler {
stateDrawable.addState(arr, colorDrawable);
stateDrawable.setBounds(0, 15, vg.getRight(), vg.getBottom());
vg.setBackground(stateDrawable);
if (android.os.Build.VERSION.SDK_INT >= 16) {
vg.setBackground(stateDrawable);
} else {
vg.setBackgroundDrawable(stateDrawable);
}
}
}
@@ -299,7 +303,12 @@ export class SegmentedBarStyler implements style.Styler {
ensureSegmentedBarColorDrawableClass();
for (let tabIndex = 0; tabIndex < tabHost.getTabWidget().getTabCount(); tabIndex++) {
let vg = <android.view.ViewGroup>tabHost.getTabWidget().getChildTabViewAt(tabIndex);
vg.setBackground(nativeValue[tabIndex]);
if (android.os.Build.VERSION.SDK_INT >= 16) {
vg.setBackground(nativeValue[tabIndex]);
} else {
vg.setBackgroundDrawable(nativeValue[tabIndex]);
}
}
}

View File

@@ -79,7 +79,12 @@ export module ad {
backgroundDrawable = new org.nativescript.widgets.BorderDrawable(density, v.toString());
refreshBorderDrawable(v, <org.nativescript.widgets.BorderDrawable>backgroundDrawable);
nativeView.setBackground(backgroundDrawable);
if (getSDK() >= 16) {
nativeView.setBackground(backgroundDrawable);
} else {
nativeView.setBackgroundDrawable(backgroundDrawable);
}
}
else {
refreshBorderDrawable(v, <org.nativescript.widgets.BorderDrawable>backgroundDrawable);
@@ -96,12 +101,21 @@ export module ad {
// reset the value with the default native value
if (v instanceof button.Button) {
let nativeButton = new android.widget.Button(nativeView.getContext());
nativeView.setBackground(nativeButton.getBackground());
if (getSDK() >= 16) {
nativeView.setBackground(nativeButton.getBackground());
} else {
nativeView.setBackgroundDrawable(nativeButton.getBackground());
}
}
else {
let viewClass = types.getClass(v);
if (_defaultBackgrounds.has(viewClass)) {
nativeView.setBackground(_defaultBackgrounds.get(viewClass));
if (getSDK() >= 16) {
nativeView.setBackground(_defaultBackgrounds.get(viewClass));
} else {
nativeView.setBackgroundDrawable(_defaultBackgrounds.get(viewClass));
}
}
}