Android ContextMenu在onCreate方法中启动?
是否可以在 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);
is it possible to start a context menu on the onCreate method? I know its probably bad design ethics but I have my resons!! I've tried the:
registerForContextMenu(this.getCurrentFocus());
But its not working.. So does anyone have any better ideas?
Many thanks in advance!
@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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要对某些小部件执行
registerForContextMenu()
,然后使用openContextMenu()
。不过,我同意你的结论,这是一个糟糕的设计。You need to do
registerForContextMenu()
for some widget, then useopenContextMenu()
. However, I agree with your conclusion that this is a bad design.