我有一个带有EditText和Seekbar的Alretdialog。通过使用Seekbar,我想更改编辑文本的背景颜色 更改搜索条颜色有效,但不会更改编辑文本背景颜色。
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
}
};
希望你理解我的意思......
答案 0 :(得分:0)
ifound prob.as你添加了一次多次调用的dynamicical.newSubjectEdit.so它被覆盖了。对于seekbar seekbar.OnSeekBarChangeListener给你seekbar as arg。引用它。所以它给出了正确的对象