RatingBar的使用和显示错误信息

在布局文件中:
<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);// 隐藏软键盘

		}

	}


你可能感兴趣的:(RatingBar的使用和显示错误信息)