改变的TextView颜色取决于搜索栏的进展 [英] Changing the TextView color depending on the progress of a SeekBar
本文介绍了改变的TextView颜色取决于搜索栏的进展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图改变颜色的的TextView
取决于搜索栏
的进度如下:
- 0-25% - >绿色
- 25%-50% - >黄色等...
当我用下面的code时,的TextView
不显示值了。
我将不胜AP preciate任何帮助!
code:
公共无效onProgressChanged(搜索栏搜索栏,INT进步,
布尔FROMUSER)
{
textView.setText(将String.valueOf(进度+%));
如果(进度> = 25安培;&安培;进步与LT; 50)
textView.setTextColor(R.color.Yellow);
否则,如果(进度> = 50安培;&安培;进步与LT; 75)
textView.setTextColor(R.color.Orange);
否则,如果(进度> = 75安培;&安培;进度< = 100)
textView.setTextColor(R.color.Red);
其他
textView.setTextColor(R.color.Green);
}
XML:
<的TextView
机器人:ID =@ + ID / ET
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=@字符串/ tvProgress
机器人:文字颜色=@色/绿
机器人:TEXTSIZE =25dp
机器人:文字样式=大胆
机器人:layout_gravity =中心
机器人:layout_marginBottom =5DP
/>
解决方案
我不明白是什么问题,但我的工作,它工作很细的我。我已附上了放还的屏幕截图。请检查。
的main.xml
<滚动型机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT> < RelativeLayout的机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT> < TextView的机器人:ID =@ + ID / aksharTextView
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=afadjklhfg
机器人:paddingTop =10dip
机器人:layout_below =@ + ID / arialTextView/> <搜索栏的android:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ ID / aksharTextView
机器人:填充=10dip
机器人:ID =@ + ID /搜索栏/>
< / RelativeLayout的>
< /滚动型>
的onCreate()
seekBar.setOnSeekBarChangeListener(新OnSeekBarChangeListener(){ 公共无效onStopTrackingTouch(搜索栏为arg0){
// TODO自动生成方法存根 } 公共无效onStartTrackingTouch(搜索栏为arg0){
// TODO自动生成方法存根 } 公共无效onProgressChanged(搜索栏为arg0,INT进步,布尔ARG2){
aksharTextView.setText(进度+);
如果(进度> = 25安培;&安培;进步与LT; 50)
aksharTextView.setTextColor(Color.BLUE);
否则,如果(进度> = 50安培;&安培;进步与LT; 75)
aksharTextView.setTextColor(Color.WHITE);
否则,如果(进度> = 75安培;&安培;进度< = 100)
aksharTextView.setTextColor(Color.GREEN);
其他
aksharTextView.setTextColor(Color.RED);
}
});
输出屏幕
I am trying to change the color of the TextView
depending on the SeekBar
's progress as following:
- 0-25% -> green
- 25%-50% -> yellow and so on...
When I using the following code, the TextView
doesn't show the value anymore.
I would greatly appreciate any help!
Code:
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser)
{
textView.setText(String.valueOf(progress + "%"));
if(progress >= 25 && progress < 50)
textView.setTextColor(R.color.Yellow);
else if(progress >= 50 && progress < 75)
textView.setTextColor(R.color.Orange);
else if(progress >= 75 && progress <= 100)
textView.setTextColor(R.color.Red);
else
textView.setTextColor(R.color.Green);
}
XML:
<TextView
android:id="@+id/eT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tvProgress"
android:textColor="@color/Green"
android:textSize="25dp"
android:textStyle="bold"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
/>
解决方案
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
这篇关于改变的TextView颜色取决于搜索栏的进展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文