0
我得到了一個帶有EditText和Seekbar的Alretdialog。通過使用Seekbar,我想更改我的edittext的背景顏色。
更改seekbar顏色有效,但不能更改edittext背景顏色。Android:Alertbuilder在運行時改變顏色
EditText newSubjectEdit;
SeekBar colorSeeker;
Builder subjectAlert;
LinearLayout lg;
private Builder getNewSubjectAlert() {
subjectAlert = new AlertDialog.Builder(this);
lg = new LinearLayout(getApplicationContext());
...
newSubjectEdit = new EditText(getApplicationContext());
...
lg.addView(newSubjectEdit);
colorSeeker = new SeekBar(getApplicationContext());
colorSeeker.setOnSeekBarChangeListener(seekBarChangeListener);
...
lg.addView(colorSeeker);
subjectAlert.setView(lg);
// set ok and cancel ...
聽衆:
SeekBar.OnSeekBarChangeListener seekBarChangeListener = new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
seekBar.setBackgroundColor(color); // works !!
newSubjectEdit.setBackgroundColor(color); // doesn't work
}
};
希望你明白我的意思是......
好的,但我如何訪問和編輯EditText? – 2011-01-24 22:41:34