[英]How can I set the color of android rating bar's stroke? (Not the color of the stars but the BORDER)
[英]Rating bar, how to get the number of stars?
我的程序中有一個編輯文本和一個評分欄。 我正在檢查用戶是否在編輯文本中包含3個以上的字符,並且對於評分欄,它應具有大於0.5星的字符(基本上是檢查它們是否至少單擊了其中任何一個)。
final EditText commentbox = (EditText)findViewById(R.id.comment);
final RatingBar rating = (RatingBar)findViewById(R.id.rating);
final Button feedbackbutton = (Button)findViewById(R.id.submit);
final TextWatcher watcher = new TextWatcher(){
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if(commentbox.length() >= 3 && rating.getNumStars() >=0.5){
feedbackbutton.setEnabled(true);
feedbackbutton.setBackgroundColor(Color.parseColor("#369742"));
} else {
feedbackbutton.setEnabled(false);
feedbackbutton.setBackgroundColor(Color.parseColor("#ffcacaca"));
}
}
};
commentbox.addTextChangedListener(watcher);
rating.setOnRatingBarChangeListener((this));
因此,您可以看到它必須滿足這些條件才能啟用按鈕並更改其背景顏色。 但是,一旦我在編輯文本中寫入了3個以上的字符,該按鈕就會啟用並更改其顏色。 它不是在尋找等級欄條件。
有人能幫助我嗎
要從評級值獲得評級:
float ratingValue = rating.getRating();
添加監聽器:
rating.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar arg0, float rateValue, boolean arg2) {
// TODO Auto-generated method stub
Log.d("Rating", "your selected value is :"+rateValue);
}
});
feedbackbutton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
//Getting the rating and displaying it on the toast
String rating=String.valueOf(rating.getRating());
Toast.makeText(getApplicationContext(), rating, Toast.LENGTH_LONG).show();
}
});
希望它能解決您的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.