使用setCustom可以重设图例,而不被修改。
List lstLegendEntry = new ArrayList<>();
Legend.LegendForm form = legend.getForm();
float formSize = legend.getFormSize();
float formLineWidth = legend.getFormLineWidth();
DashPathEffect dashPathEffect =legend.getFormLineDashEffect();
lstLegendEntry.add(new LegendEntry(FAIL,form,formSize,formLineWidth
,dashPathEffect,Color.RED));
lstLegendEntry.add(new LegendEntry(PASS,form,formSize,formLineWidth
,dashPathEffect,Color.rgb(11, 157, 107)));
lstLegendEntry.add(new LegendEntry(DNF,form,formSize,formLineWidth
,dashPathEffect,Color.GRAY));
lstLegendEntry.add(new LegendEntry(CANCEL,form,formSize,formLineWidth
,dashPathEffect,Color.BLUE));
legend.setCustom(lstLegendEntry);