如何更改 MPAndroidChart 中饼图描述的文本颜色?
How to change text color of pie chart description in MPAndroidChart?
我正在使用 MPAndroidChart 库创建饼图。在我的应用程序中,我有一个黑色背景,饼图描述的文本颜色默认为灰色,这对我不利。我无法更改它。
如何更改描述的文字颜色?
我的饼图:
使用setDescriptionColor(int color)
方法
chart.setDescriptionColor(getResources().getColor(R.color.your_color));
文本颜色也可以从这里更改。
- 进入你的图书馆"MPChartLib"
- 首先:- 包:- 图表---> Chart.java
- 然后开始:- init();
- 更改饼图描述文字颜色:-
我发现这段代码可能有用 here。
public void setDescriptionColor(int color) {
mDescPaint.setColor(color);
}
从这里更改其他文本颜色:-
以下代码同源。
mDescPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mDescPaint.setColor(Color.BLACK);
mDescPaint.setTextAlign(Align.RIGHT);
mDescPaint.setTextSize(Utils.convertDpToPixel(9f));
mInfoPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mInfoPaint.setColor(Color.rgb(0, 0, 0)); // black
mInfoPaint.setTextAlign(Align.CENTER);
mInfoPaint.setTextSize(Utils.convertDpToPixel(15f));
mDrawPaint = new Paint(Paint.DITHER_FLAG);
现在,我的事情发生了一点点变化。因此,我所知的最新解决方案是:
description.setTextColor(ContextCompat.getColor(context, R.color.your_color));
其中 description
代表 Description description = new Description();
我正在使用 MPAndroidChart 库创建饼图。在我的应用程序中,我有一个黑色背景,饼图描述的文本颜色默认为灰色,这对我不利。我无法更改它。
如何更改描述的文字颜色?
我的饼图:
使用setDescriptionColor(int color)
方法
chart.setDescriptionColor(getResources().getColor(R.color.your_color));
文本颜色也可以从这里更改。
- 进入你的图书馆"MPChartLib"
- 首先:- 包:- 图表---> Chart.java
- 然后开始:- init();
- 更改饼图描述文字颜色:-
我发现这段代码可能有用 here。
public void setDescriptionColor(int color) { mDescPaint.setColor(color); }
从这里更改其他文本颜色:-
以下代码同源。
mDescPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mDescPaint.setColor(Color.BLACK); mDescPaint.setTextAlign(Align.RIGHT); mDescPaint.setTextSize(Utils.convertDpToPixel(9f)); mInfoPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mInfoPaint.setColor(Color.rgb(0, 0, 0)); // black mInfoPaint.setTextAlign(Align.CENTER); mInfoPaint.setTextSize(Utils.convertDpToPixel(15f)); mDrawPaint = new Paint(Paint.DITHER_FLAG);
现在,我的事情发生了一点点变化。因此,我所知的最新解决方案是:
description.setTextColor(ContextCompat.getColor(context, R.color.your_color));
其中 description
代表 Description description = new Description();