- 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"