Android:Alertbuilder 在运行时更改颜色
我得到了一个带有 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
}
};
希望你明白我的意思……
I got one Alretdialog with an EditText and a Seekbar. By using the Seekbar, i want to change the background color of my edittext.
Changing the seekbar color works, but not changing the edittext background color.
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 ...
the listener:
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
}
};
hope you understand what i mean...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果发现问题。因为您添加了多次调用的视图dynamicalle.newSubjectEdit。因此它被覆盖。并且对于seekbar seebar.OnSeekBarChangeListener为您提供seekbar作为arg。它被引用。所以它给出了正确的对象
ifound prob.as you have add view dynamicalle.newSubjectEdit called more than once.so it is overridden.and for seekbar seekbar.OnSeekBarChangeListener gives you seekbar as arg. which is referenced.so it gives correct object