- RatingBar 星级评分控件
1:星星评分样式 xml文件内容 <RatingBar android:id="@+id/rb_normal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:isIndicator="false" android:numStars="5" android:stepSize="0.5" /> -相关属性 isIndicator:是否用作指示,默认false,用户无法更改 numStars:显示多少个星星,整数 rating:默认评分值,浮点数 stepSize:评分每次增加的值,浮点数 -事件 OnRatingBarChangeListener事件
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.ac_coordinator_layout); RatingBar rb = findViewById(R.id.rb_normal); rb.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() { @Override public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { Toast.makeText(Coordinator_LayoutActivity.this, "rating" + String.valueOf(rating), Toast.LENGTH_SHORT).show(); } }); }
2:自定义评分样式
<RatingBar android:id="@+id/rb_normal" style="@style/roomRatingBar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:isIndicator="false" android:numStars="5" android:stepSize="0.5" /> style.xml内容 : <style name="roomRatingBar" parent="@android:style/Widget.RatingBar"> <item name="android:progressDrawable">@drawable/ratingbar_full</item> <item name="android:minHeight">24dp</item> <item name="android:maxHeight">24dp</item> </style> drawable/ratingbar_full.xml : <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@android:id/background" android:drawable="@drawable/smile" /> <item android:id="@android:id/progress" android:drawable="@drawable/smiley_pro" /> </layer-list> @android:id/background:背景图片,默认时显示 @android:id/progress:前景图片,点击时显示 图片样式可自由替换
- SeekBar 拖动条
<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:max="100"
android:thumb="@drawable/smiley_pro"
android:layout_height="wrap_content" />
--属性
max:滑动条的最大值
progress:滑动条的当前值
secondaryProgress:二级滑动条的进度
thumb:滑块的drawable
--事件 OnSeekBarChangeListener
SeekBar seekBar = findViewById(R.id.seekBar);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override 进度条发生改变时触发
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
Toast.makeText(Coordinator_LayoutActivity.this, "当前进度值 :" + progress + "/100", Toast.LENGTH_SHORT).show();
}
@Override 按住seekbar时触发
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override 放开时触发
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
- 进度条
常见属性:
max:进度条的最大值
progress:进度条已完成进度值
progressDrawable:设置轨道对应的Drawable对象
indeterminate:进度条是否精确显示进度
getMax()返回进度条范围的上限
getProgress()返回进度
incrementProgressBy(3)指定增加的进度
- 滚动条
fullScroll(ScrollView.FOCUS_DOWN)滚动到底部
fullScroll(ScrollView.FOCUS_UP)滚动到顶部
scrollbarThumbVertical垂直方向滑块的图片
scrollbarThumbHorizontal水平方向滑块图片
setVerticalScrollBarEnabled(false)隐藏滑块
- Button
在布局文件中添加Button控件后,系统默认会对Button中的英文字母进行大写转换,可通过 btn.setAllCaps(false)属性禁用这 一 特性。
xml文件中为android:textAllCaps="false"