2

我想知道在单击或触摸文本视图后是否可以更改颜色。文件中有多个文本视图,我想知道选择某个文本视图时需要做什么。目前我只能改变颜色

这是我的代码?

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_image);

    ImageView image = (ImageView) findViewById(R.id.imageView1);
    SeekBar sliderBar = (SeekBar) findViewById(R.id.sliderBar);

    paint = new Paint();
    paint.setColor(Color.RED);

    sliderBar.setProgress(-3);
    sliderBar.incrementProgressBy(1);
    sliderBar.setMax(6);

    category1 = (TextView) findViewById(R.id.category1);
    category2 = (TextView) findViewById(R.id.category2);
    category3 = (TextView) findViewById(R.id.category3);
    category4 = (TextView) findViewById(R.id.category4);
    category5 = (TextView) findViewById(R.id.category5);
    category6 = (TextView) findViewById(R.id.category6);
    category7 = (TextView) findViewById(R.id.category7);
    category8 = (TextView) findViewById(R.id.category8);
    category9 = (TextView) findViewById(R.id.category9);
    textProgress = (TextView) findViewById(R.id.sliderText);

    category1.setClickable(true);
    category2.setClickable(true);
    category3.setClickable(true);
    category4.setClickable(true);
    category5.setClickable(true);
    category6.setClickable(true);
    category7.setClickable(true);
    category8.setClickable(true);
    category9.setClickable(true);
    sliderBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
    {

        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) 
        {

            // TODO Auto-generated method stub

            textProgress.setText("The value is: "+ (-3+progress) );

            if(progress ==0) //slider is at -3
            {
                if(category1.isSelected())
                {
                category1.setTextColor(Color.BLUE);
                }
                if(category2.isSelected())
                {
                category2.setTextColor(Color.BLUE);
                }

            }


            else if(progress==1) //slider is at -2
            {
                category1.setTextColor(Color.BLACK);
            }

            else if(progress==2) //slider is at -1
            {
                category1.setTextColor(Color.BLUE);

            }

            else if (progress==3) //slider is at 0
            {
                category1.setTextColor(Color.BLACK);

            }

            else if (progress==4) //slider is at 1
            {
                category1.setTextColor(Color.DKGRAY);
            }

            else if (progress==5) //slider is at 2
            {
                category1.setTextColor(Color.MAGENTA);

            }

            else if (progress==6) //slider is at 3
            {
                category1.setTextColor(Color.RED);
            }

        }

        public void onStartTrackingTouch(SeekBar arg0) {
            // TODO Auto-generated method stub

        }

        public void onStopTrackingTouch(SeekBar arg0) {
            // TODO Auto-generated method stub

        }

    }); 

}

我想知道当我选择不同的类别时,我可以使用搜索栏更改文本的颜色,但只能更改所选文本视图(类别“X”)的颜色。谢谢。

4

0 回答 0