在布局檔案中:
<RatingBar
style="@style/myRatingBar" //使用樣式
android:layout_marginLeft="10dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rbar">
</RatingBar>
在values檔案夾下的 styles.xml檔案夾中
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="myRatingBar" parent="@android:style/Widget.RatingBar">
<item name="android:progressDrawable">@drawable/rating_bar</item> //重新定義圖案
<item name="android:minHeight">16dip</item> //最小高度
<item name="android:maxHeight">16dip</item> //最大高度
</style>
</resources>
顯示錯誤資訊
/** * 顯示錯誤資訊 * * @param c * @param editText * @param str */public static void showEditTextError(Context c, EditText editText, int str){Selection.selectAll(editText.getText());editText.setError(c.getResources().getString(str));editText.requestFocus();InputMethodManager imm = (InputMethodManager) c.getSystemService(Context.INPUT_METHOD_SERVICE);View view = ((Activity) c).getCurrentFocus();if (view != null){imm.hideSoftInputFromWindow(view.getWindowToken(), 0);// 隱藏軟鍵盤}}/** * 顯示錯誤資訊 * * @param c * @param editText * @param str */public static void showAutoCompleteTextViewError(Context c, AutoCompleteTextView editText, int str){Selection.selectAll(editText.getText());editText.setError(c.getResources().getString(str));editText.requestFocus();InputMethodManager imm = (InputMethodManager) c.getSystemService(Context.INPUT_METHOD_SERVICE);View view = ((Activity) c).getCurrentFocus();if (view != null){imm.hideSoftInputFromWindow(view.getWindowToken(), 0);// 隱藏軟鍵盤}}