首先这不是完整的代码
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
Toast toast=Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_HORIZONTAL, 0, 0);
View view=toast.getView();
switch(buttonView.getId())
{
case R.id.chkRed: if(chkRed.isChecked())
{
chkGreen.setChecked(false);
chkBlue.setChecked(false);
chkYellow.setChecked(false);
toast.setText("You Selected Red");
toast.setGravity(Gravity.NO_GRAVITY,buttonView.getRight(), chkRed.getTop());
//top does not align
//it align perfectly to right of checkbox
view.setBackgroundColor(Color.RED);
}
break;
}
}
所以现在的问题是我想在复选框旁边显示吐司,我尝试使用setGravity()
,但它只是没有处理,并且已经被击中并尝试了很长时间,但没有任何进展
如何在复选框旁边显示吐司?