如何在弹出菜单中动态添加单选按钮?

时间:2019-11-11 11:32:49

标签: java android

Actions action = new Action(driver);

action.moveToElement(firstNameElement).click().sendKeys(firstNameElement, lowercase([FirstName])).build().perform();

我正在尝试使单选按钮弹出菜单,我能够添加复选框,但无法添加单选按钮,我该怎么做。

1 个答案:

答案 0 :(得分:0)

这对我有用。

public void showPopup(View v) {


    PopupMenu popup = new PopupMenu(this.getContext(), v, Gravity.RIGHT);
    popup.setOnMenuItemClickListener(this);
    //        popup.inflate(R.menu.hc_popup_check);
    //        popup.getMenu().findItem(R.id.item1).setChecked(true);
    int groupId = 1;
    popup.getMenu().add(groupId, 1, 1, "Share").setCheckable(true); 
    //.setChecked
    popup.getMenu().add(groupId, 2, 2, "Comment").setCheckable(true);
    popup.show();
}