下面的代码显示警报对话框中的6颗星,我想要只显示3颗星,请给我一些提示。
public void ShowDialog()
{
final AlertDialog.Builder popDialog = new AlertDialog.Builder(this);
final RatingBar rb = new RatingBar(this);
popDialog.setIcon(android.R.drawable.btn_star_big_on);
rb.setRating(0);
rb.setNumStars(3);
popDialog.setTitle("Vote!! ");
popDialog.setView(rb);
// Button OK
popDialog.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
popDialog.create();
popDialog.show();
}
答案 0 :(得分:0)
final AlertDialog.Builder popDialog = new AlertDialog.Builder(
getActivity());
final RatingBar rb = new RatingBar(getActivity());
popDialog.setIcon(android.R.drawable.btn_star_big_on);
rb.setRating(0);
rb.setNumStars(3);
popDialog.setTitle("Vote!! ");
popDialog.setView(rb);
// Button OK
popDialog.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
popDialog.show();
// This is the trick
rb.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
答案 1 :(得分:0)
尝试设置RatingBar的布局,同时尝试rb.setMax()获取最大星星。
RatingBar rb = new RatingBar(context, null, android.R.attr.ratingBarStyleSmall);
rb.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
rb.setIsIndicator(true);
rb.setNumStars(3);
rb.setMax(3);