Changing the TextView color depending on the progress of a SeekBar

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 22:02:29

I don't get what the problem is, but I worked on it and it works very fine for me. I have attached the screen shots of the out put also. Please check.

main.xml

 <ScrollView  android:layout_width="wrap_content"
     android:layout_height="wrap_content">

     <RelativeLayout  android:layout_width="wrap_content"
         android:layout_height="wrap_content">



            <TextView  android:id="@+id/aksharTextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="afadjklhfg"
                android:paddingTop="10dip"
                android:layout_below="@+id/arialTextView"/>



            <SeekBar  android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/aksharTextView"
                android:padding="10dip"
                android:id="@+id/seekbar"/>
     </RelativeLayout>


 </ScrollView>

onCreate()

 seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

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

            }

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

            }

            public void onProgressChanged(SeekBar arg0, int progress, boolean arg2) {
                aksharTextView.setText(progress+"");
                if(progress >= 25 && progress < 50)
                    aksharTextView.setTextColor(Color.BLUE);
                else if(progress >= 50 && progress < 75)
                    aksharTextView.setTextColor(Color.WHITE);
                else if(progress >= 75 && progress <= 100)
                    aksharTextView.setTextColor(Color.GREEN);
                else 
                    aksharTextView.setTextColor(Color.RED);
            }
        });

OutPut Screens

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!