Skip to content

Commit

Permalink
[TIMOB-27117] Android: Fixed TabGroup bar background color to not be …
Browse files Browse the repository at this point in the history
…transparent on Android 4.4 (#10930)

- Modified to fetch colors from ActionBar style XML for backward compaitibility with apps built before Titanium 8.0.0
  • Loading branch information
jquick-axway authored and lokeshchdhry committed Jun 11, 2019
1 parent 6f54dce commit 16b2daf
Showing 1 changed file with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@
import android.view.View;
import android.view.ViewGroup;

import org.appcelerator.kroll.common.Log;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.titanium.TiBaseActivity;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.proxy.ActivityProxy;
import org.appcelerator.titanium.util.TiColorHelper;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiRHelper;
import org.appcelerator.titanium.view.TiInsetsProvider;
import org.appcelerator.titanium.view.TiUIView;

Expand Down Expand Up @@ -118,16 +120,21 @@ public TiUIAbstractTabGroup(final TabGroupProxy proxy, TiBaseActivity activity)
{
super(proxy);

// Getting the value for colorPrimary from the currently used theme.
TypedValue colorPrimaryTypedValue = new TypedValue();
TypedArray colorPrimary =
activity.obtainStyledAttributes(colorPrimaryTypedValue.data, new int[] { android.R.attr.colorPrimary });
this.colorPrimaryInt = colorPrimary.getColor(0, 0);
// Getting the value for textColorPrimary for the currently used theme.
TypedValue typedValue = new TypedValue();
TypedArray textColor =
activity.obtainStyledAttributes(typedValue.data, new int[] { android.R.attr.textColorPrimary });
this.textColorInt = textColor.getColor(0, 0);
// Fetch primary background and text colors from ActionBar style assigned to activity theme.
// Note: We use ActionBar style for backward compatibility with Titanium versions older than 8.0.0.
this.colorPrimaryInt = 0xFF212121; // Default to dark gray.
this.textColorInt = 0xFFFFFFFF; // Default to white.
try {
int styleAttributeId = TiRHelper.getResource("attr.actionBarStyle");
int[] idArray = new int[] { TiRHelper.getResource("attr.colorPrimary"),
TiRHelper.getResource("attr.textColorPrimary") };
TypedArray typedArray = activity.obtainStyledAttributes(null, idArray, styleAttributeId, 0);
this.colorPrimaryInt = typedArray.getColor(0, this.colorPrimaryInt);
this.textColorInt = typedArray.getColor(1, this.textColorInt);
typedArray.recycle();
} catch (Exception ex) {
Log.e(TAG, "Failed to fetch color from theme.", ex);
}

this.tabGroupPagerAdapter = new TabGroupFragmentPagerAdapter(activity.getSupportFragmentManager());

Expand Down

0 comments on commit 16b2daf

Please sign in to comment.