0

是否可以在 onCreate 方法上启动上下文菜单?我知道这可能是糟糕的设计道德,但我有我的理由!我试过了:

registerForContextMenu(this.getCurrentFocus());

但它不起作用..那么有人有更好的想法吗?

提前谢谢了!

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LinearLayout layout = new LinearLayout(this);
    layout.setLayoutParams(new
    LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    //Button button = new Button(this);
    //button.setLayoutParams(new
    //LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    //button.setText("my button");

    TextView text = new TextView(this);
    text.setLayoutParams(new
    LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    layout.addView(text);
    setContentView(layout);

    registerForContextMenu(text);
    openContextMenu(layout);
4

1 回答 1

0

你需要做registerForContextMenu()一些小部件,然后使用openContextMenu(). 但是,我同意你的结论,即这是一个糟糕的设计。

于 2010-09-01T16:09:34.337 回答