改变取决于搜索栏
问题描述:
我试图改变TextView
的取决于SeekBar
的进步颜色如下的进步TextView的颜色:改变取决于搜索栏
- 0-25% - >绿
- 25%-50% - >黄色等等......
当我使用下面的代码时,TextView
不再显示该值。
我将不胜感激任何帮助!
代码:
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"
/>
答
我不明白是什么问题,但我的工作就可以了,它工作得罚款我。我也附上了出来的屏幕截图。请检查。
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);
}
});
个输出屏幕
+0
非常感谢!我实际上有相同的代码,并没有结束。我需要仔细观察,因为这是一个逃避我眼睛的小事。 – iamdanchiv
+0
尝试使用Color.BLUE,而不是R.color.blue。它可能工作。这是唯一的区别 –
它是否给任何错误?你确定字符串R.color.Yellow,R.color.Orange和R.color.Red具有合适的十六进制值吗? – Sana
它看起来像你没有用setText更新textview。你必须做textView.setText(progress);在每个条件下 –
该代码应该没有任何问题。你确定你在右边的'TextView'上设置了文本+颜色吗? – Luksprog