本文介绍了Android的我有例外color.parsecolor错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有parsecolor的异常问题,当我去向下跌破20,应用程序崩溃的值,其余的是罚款...你能告诉我为什么吗?
I have a problem with an exception of parsecolor, when I go down below a value of 20, the application crashes, the rest is fine ... can you tell me why?
我简单的code是:
公共类ColoreTesto延伸活动{
public class ColoreTesto extends Activity {
private SeekBar seekred, seekgreen, seekblu;
private TextView seekred_txt, seekgreen_txt, seekblu_txt;
private TextView esempio;
private int redtxt, greentxt, blutxt;
private int progressred, progressgreen, progressblu;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.coloretesto);
/* RIFERIMENTO AL GRUPPO DI VARIABILI SHARED*/
final SharedPreferences settings = getSharedPreferences("settings", 0);
final SharedPreferences.Editor editor = settings.edit();
esempio = (TextView)findViewById(R.id.txt_esempio);
/****
* SEEKBAR RED
****/
seekred = (SeekBar) findViewById (R.id.seekRed);
seekred.setMax(255);
seekred_txt = (TextView)findViewById(R.id.textRed);
/*CARICARE IL VALORE DELLA SEEKBAR*/
redtxt = settings.getInt("redtxt", 255); /*UNA VARIABILE DEL GRUPPO*/
seekred_txt.setText(redtxt + getString(R.string.red));
seekred.setProgress(redtxt);
// CAMBIAMENTO DEL VALORE DELLA SEEKBAR
seekred.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
//spostamento
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
seekred_txt.setText(progress + getString(R.string.red));
esempio.setTextColor(Color.parseColor("#" + Integer.toHexString(progress) + Integer.toHexString(greentxt) + Integer.toHexString(blutxt)));
}
//inizio dello spostamento
public void onStartTrackingTouch(SeekBar seekBar) {
}
//fine dello spostamento
public void onStopTrackingTouch(SeekBar seekBar) {
redtxt = seekBar.getProgress();
}
});
/****
* SEEKBAR GREEN
****/
seekgreen = (SeekBar) findViewById (R.id.seekGreen);
seekgreen.setMax(255);
seekgreen_txt = (TextView)findViewById(R.id.textGreen);
/*CARICARE IL VALORE DELLA SEEKBAR*/
greentxt = settings.getInt("greentxt", 255); /*UNA VARIABILE DEL GRUPPO*/
seekgreen_txt.setText(greentxt + getString(R.string.green));
seekgreen.setProgress(greentxt);
// CAMBIAMENTO DEL VALORE DELLA SEEKBAR
seekgreen.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
//spostamento
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
seekgreen_txt.setText(progress + getString(R.string.green));
esempio.setTextColor(Color.parseColor("#" + Integer.toHexString(redtxt) + Integer.toHexString(progress) + Integer.toHexString(blutxt)));
}
//inizio dello spostamento
public void onStartTrackingTouch(SeekBar seekBar) {
}
//fine dello spostamento
public void onStopTrackingTouch(SeekBar seekBar) {
greentxt = seekBar.getProgress();
}
});
/****
* SEEKBAR BLU
****/
seekblu = (SeekBar) findViewById (R.id.seekBlu);
seekblu.setMax(255);
seekblu_txt = (TextView)findViewById(R.id.textBlu);
/*CARICARE IL VALORE DELLA SEEKBAR*/
blutxt = settings.getInt("blutxt", 255); /*UNA VARIABILE DEL GRUPPO*/
seekblu_txt.setText(blutxt + getString(R.string.blu));
seekblu.setProgress(blutxt);
// CAMBIAMENTO DEL VALORE DELLA SEEKBAR
seekblu.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
//spostamento
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
seekblu_txt.setText(progress + getString(R.string.blu));
esempio.setTextColor(Color.parseColor("#" + Integer.toHexString(redtxt) + Integer.toHexString(greentxt) + Integer.toHexString(progress)));
}
//inizio dello spostamento
public void onStartTrackingTouch(SeekBar seekBar) {
}
//fine dello spostamento
public void onStopTrackingTouch(SeekBar seekBar) {
blutxt = seekBar.getProgress();
}
});
}
}
感谢。
推荐答案
这是因为你想分配RGB格式,而不是十六进制,请尝试以下code:
That's because you're trying to assign RGB format instead of hexadecimal, Try the following code:
Color mColor = new Color();
mColor.red(redvalue);
mColor.green(greenvalue);
mColor.blue(bluevalue);
esempio.setTextColor(mColor);
这篇关于Android的我有例外color.parsecolor错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!