<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="评分"
android:textColor="@color/string_color"
android:textSize="@dimen/string_size" />
<RatingBar
android:id="@+id/rb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:stepSize="0.5" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="拖动条"
android:textColor="@color/colorAccent"
android:textSize="@dimen/string_size" />
<SeekBar
android:id="@+id/sb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="255"
android:padding="30dp" />
<TextView
android:id="@+id/tv_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我是显示的文字"
android:textSize="@dimen/string_size" />
</LinearLayout>
java页面
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.RatingBar;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private RatingBar rb;
private SeekBar sb;
private TextView tv_color;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
// 评分
rb.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
Toast.makeText(MainActivity.this, ratingBar.getRating() + "", Toast.LENGTH_SHORT).show();
}
});
// 拖动条
sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// Toast.makeText(MainActivity.this, seekBar.getProgress()+"", Toast.LENGTH_SHORT).show();
tv_color.setTextColor(Color.argb(50, 0, progress, 0));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
Toast.makeText(MainActivity.this, "拖动开始", Toast.LENGTH_SHORT).show();
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
Toast.makeText(MainActivity.this, "拖动结束", Toast.LENGTH_SHORT).show();
}
});
}
public void initView() {
rb = (RatingBar) findViewById(R.id.rb);
sb = (SeekBar) findViewById(R.id.sb);
tv_color = (TextView) findViewById(R.id.tv_color);
}
}