@@ -63,23 +63,6 @@ function onItemsPropertyChanged(data: dependencyObservable.PropertyChangeData) {
63
63
var tabHost = < android . widget . TabHost > view . android ;
64
64
var tabIndex : number ;
65
65
66
- if ( view . selectedBackgroundColor ) {
67
- ensureSegmentedBarColorDrawableClass ( ) ;
68
- for ( tabIndex = 0 ; tabIndex < tabHost . getTabWidget ( ) . getTabCount ( ) ; tabIndex ++ ) {
69
- var vg = < android . view . ViewGroup > tabHost . getTabWidget ( ) . getChildTabViewAt ( tabIndex ) ;
70
-
71
- var stateDrawable = new android . graphics . drawable . StateListDrawable ( ) ;
72
-
73
- var arr = ( < any > Array ) . create ( "int" , 1 ) ;
74
- arr [ 0 ] = R_ATTR_STATE_SELECTED ;
75
- var colorDrawable : android . graphics . drawable . ColorDrawable = new SegmentedBarColorDrawableClass ( view . selectedBackgroundColor . android )
76
- stateDrawable . addState ( arr , colorDrawable ) ;
77
- stateDrawable . setBounds ( 0 , 15 , vg . getRight ( ) , vg . getBottom ( ) ) ;
78
-
79
- vg . setBackgroundDrawable ( stateDrawable ) ;
80
- }
81
- }
82
-
83
66
for ( tabIndex = 0 ; tabIndex < tabHost . getTabWidget ( ) . getTabCount ( ) ; tabIndex ++ ) {
84
67
var tabChild = < android . view . ViewGroup > tabHost . getTabWidget ( ) . getChildTabViewAt ( tabIndex ) ;
85
68
var t = < android . widget . TextView > tabChild . getChildAt ( 1 ) ;
@@ -292,6 +275,45 @@ export class SegmentedBarStyler implements style.Styler {
292
275
} ;
293
276
}
294
277
278
+ // selectedBackgroundColor methods
279
+ private static setSelectedBackgroundColorProperty ( v : view . View , newValue : any ) {
280
+ ensureSegmentedBarColorDrawableClass ( ) ;
281
+ let tabHost = < android . widget . TabHost > v . _nativeView ;
282
+ for ( let tabIndex = 0 ; tabIndex < tabHost . getTabWidget ( ) . getTabCount ( ) ; tabIndex ++ ) {
283
+ let vg = < android . view . ViewGroup > tabHost . getTabWidget ( ) . getChildTabViewAt ( tabIndex ) ;
284
+
285
+ let stateDrawable = new android . graphics . drawable . StateListDrawable ( ) ;
286
+
287
+ let arr = ( < any > Array ) . create ( "int" , 1 ) ;
288
+ arr [ 0 ] = R_ATTR_STATE_SELECTED ;
289
+ let colorDrawable : android . graphics . drawable . ColorDrawable = new SegmentedBarColorDrawableClass ( newValue )
290
+ stateDrawable . addState ( arr , colorDrawable ) ;
291
+ stateDrawable . setBounds ( 0 , 15 , vg . getRight ( ) , vg . getBottom ( ) ) ;
292
+
293
+ vg . setBackground ( stateDrawable ) ;
294
+ }
295
+ }
296
+
297
+ private static resetSelectedBackgroundColorProperty ( v : view . View , nativeValue : Array < android . graphics . drawable . Drawable > ) {
298
+ let tabHost = < android . widget . TabHost > v . _nativeView ;
299
+ ensureSegmentedBarColorDrawableClass ( ) ;
300
+ for ( let tabIndex = 0 ; tabIndex < tabHost . getTabWidget ( ) . getTabCount ( ) ; tabIndex ++ ) {
301
+ let vg = < android . view . ViewGroup > tabHost . getTabWidget ( ) . getChildTabViewAt ( tabIndex ) ;
302
+ vg . setBackground ( nativeValue [ tabIndex ] ) ;
303
+ }
304
+ }
305
+
306
+ private static getSelectedBackgroundColorProperty ( v : view . View ) : Array < android . graphics . drawable . Drawable > {
307
+ var tabHost = < android . widget . TabHost > v . _nativeView ;
308
+ let result = [ ] ;
309
+ for ( let tabIndex = 0 ; tabIndex < tabHost . getTabWidget ( ) . getTabCount ( ) ; tabIndex ++ ) {
310
+ let background = tabHost . getTabWidget ( ) . getChildTabViewAt ( tabIndex ) . getBackground ( ) ;
311
+ result . push ( background ) ;
312
+ }
313
+
314
+ return result ;
315
+ }
316
+
295
317
public static registerHandlers ( ) {
296
318
style . registerHandler ( style . colorProperty , new style . StylePropertyChangedHandler (
297
319
SegmentedBarStyler . setColorProperty ,
@@ -301,6 +323,10 @@ export class SegmentedBarStyler implements style.Styler {
301
323
SegmentedBarStyler . setFontInternalProperty ,
302
324
SegmentedBarStyler . resetFontInternalProperty ,
303
325
SegmentedBarStyler . getFontInternalProperty ) , "SegmentedBar" ) ;
326
+ style . registerHandler ( style . selectedBackgroundColorProperty , new style . StylePropertyChangedHandler (
327
+ SegmentedBarStyler . setSelectedBackgroundColorProperty ,
328
+ SegmentedBarStyler . resetSelectedBackgroundColorProperty ,
329
+ SegmentedBarStyler . getSelectedBackgroundColorProperty ) , "SegmentedBar" ) ;
304
330
}
305
331
}
306
332
0 commit comments