【发布时间】:2019-07-24 06:26:57
【问题描述】:
我有一个游戏,我需要根据用户的输入来改变文字的颜色
我使用不同的方法在 2 个地方更改了文本,这两种方法在某些设备上都失败了,并且 textColor 在这些设备上总是变成黑色并带有白色笔划,但是我从未在任何地方的代码上添加笔划,到目前为止报告的设备是三星 Galaxy prime , 小米 Mi A2 Lite, 华为 P20 Pro, 但是我在我朋友的三星 Galaxy Prime 上尝试了游戏,它运行良好,所以我无法在我拥有的测试设备上生成这个问题
显示问题的图片,所有文字均为黑色,笔触颜色为白色
普通图片
键盘部分的第一种方法我的代码如下
btns[t].setTextColor(ContextCompat.getColor(getContext(),R.color.text_color));
当用户设置夜间模式时,我将其更改为
btns[t].setTextColor(ContextCompat.getColor(getContext(), R.color.text_color_night));
其中颜色为 text_color = #000000 / text_color_night = #ffffff
棋盘部分的第二种方法,我的代码是
private final Paint selectedBox = new Paint();
private final TextPaint letterTextNormal = new TextPaint();
private final TextPaint letterTextCorrect = new TextPaint();
private final TextPaint letterTextWrong = new TextPaint();
public PlayboardRenderer(Context con) {
letterTextNormal.setTextAlign(Align.CENTER);
letterTextNormal.setAntiAlias(true);
letterTextNormal.setTypeface(((MainActivity) con).getSelectedFont());
letterTextCorrect.setTextAlign(Align.CENTER);
letterTextCorrect.setAntiAlias(true);
letterTextCorrect.setTypeface(((MainActivity) con).getSelectedFont());
letterTextWrong.setTextAlign(Align.CENTER);
letterTextWrong.setAntiAlias(true);
letterTextWrong.setTypeface(((MainActivity) con).getSelectedFont());
}
private void drawBox(Canvas canvas, int x, int y, int row, int col, float scale, Box box, Word currentWord) {
int boxSize = (int) (BOX_SIZE * scale);
// scale paints
float textSize = (boxSize) - (boxSize / 5);
letterTextNormal.setTextSize(textSize);
letterTextCorrect.setTextSize(textSize);
letterTextWrong.setTextSize(textSize);
if (!box.isBlank() && !box.isEmpty())
if (box.getState() == Box.STATE.NORMAL) {
canvas.drawText(Character.toString(box.getChar()), x + (boxSize / 2), y + (int) (textSize * 0.9), letterTextNormal);
} else if (box.getState() == Box.STATE.WRONG) {
canvas.drawText(Character.toString(box.getChar()), x + (boxSize / 2), y + (int) (textSize * 0.9), letterTextWrong);
} else if (box.getState() == Box.STATE.CORRECT) {
canvas.drawText(Character.toString(box.getChar()), x + (boxSize / 2), y + (int) (textSize * 0.9), letterTextCorrect);
}
}
}
【问题讨论】:
-
请区分你得到的和你想要的输出,最好使用一些图像
-
我相信你说的是你分享的屏幕右上角?。如果不是,请提供清晰的图片说明问题出在哪里。
-
添加了更清晰的图片