Open marlonlom opened 4 years ago
Just found a solution - you can use this code to adjust txt color:
XAxis xaxis = chart.getXAxis();
YAxis yaxis = chart.getAxisRight();
switch (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) {
case Configuration.UI_MODE_NIGHT_YES:
xaxis.setTextColor(Color.WHITE);
yaxis.setTextColor(Color.WHITE);
break;
case Configuration.UI_MODE_NIGHT_NO:
... code for light mode ...
break;
}
@ColorInt fun Context.getColorThemeRes(@AttrRes id: Int): Int { val resolvedAttr = TypedValue() this.theme.resolveAttribute(id, resolvedAttr, true) return this.getColor(resolvedAttr.resourceId) }
val textColorPrimary = requireContext().getColorThemeRes(android.R.attr.textColorPrimary) val yAxis = chart.getAxisLeft() yAxis.textColor = textColorPrimary similar all other textcolors like radarData.setValueTextColor(textColorPrimary) lineChart.legend.textColor = textColorPrimary
The solution is simple, configure your desired color in the Light and Night Theme then set it
mPPieChartLegend.textColor = ContextCompat.getColor(requireActivity(), R.color.yourColor)
Summary When displaying the chart in dark mode/night mode, the text color isnt changing.
Expected Behavior Add support for color theme attributes as per Material Design Guidelines for Color.
Possible Solution Add support for theme attributes inside the line chart, as Material Design guidelines for Themes and Color.
Color attributes for use: colorOnSurface
When using theme color attributes, i've using this for getting the color attribute and adding it to the text color attributes for the chart (xAxis) and also in the LineDataSet.
Device:
More info: this related question on StackOverflow