【问题标题】:How to change the background color of an ImageView using for example a SeekBar?如何使用例如 SeekBar 更改 ImageView 的背景颜色?
【发布时间】:2014-10-26 20:54:10
【问题描述】:

我想做以下事情:

  1. 我有一个 LinearLayout 和几个 ImageViews,它们的 xml 中定义了背景颜色。
  2. 我有一个SeekBar
  3. 通过移动 Seekbar 我应该更改 Imageviews 背景的颜色。

我想保存默认的背景颜色但是找不到getbackgroundcolor方法,只有setbackground方法。

稍后我想在Seekbar 进行时更改颜色。

我现在有这样的东西:

public void onProgressChanged(SeekBar seekBar, int progress,
                boolean fromUser) {
    // TODO Auto-generated method stub
    int test = seekBar.getProgress();
    //textView.setText("Valami" + test);
    switch (test) {
    case 0:             
        imageView0.setBackgroundColor(Color.RED);
        imageView1.setBackground(Color.YELLOW);
        break;
    case 1:
        imageView0.setBackgroundColor(Color.BLACK);
        imageView1.setBackgroundColor(Color.BLACK);  
        break;
    case 2:
        imageView0.setBackgroundColor(Color.WHITE);
        imageView1.setBackgroundColor(Color.YELLOW);
       break;
}

我认为这不是正确的方法,我想通过获取实际的SeekBar 进度值来更改它们的颜色。例如,根据进度值对原始颜色代码添加一些值。

这是我的想法,但我不知道如何实现。

感谢您的帮助!

【问题讨论】:

标签: android colors imageview seekbar


【解决方案1】:

stkent 的建议对我有帮助。

其实这篇帖子里的答案:android color between two colors, based on percentage?对我帮助很大。

在这种情况下,Mark Renouf 的解决方案非常有帮助。

谢谢!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-14
    • 2016-01-13
    • 1970-01-01
    • 2010-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多