Android的 - openOptionsMenu中不起作用的onCreate [英] Android - openOptionsMenu doesn't work in onCreate
问题描述
有没有打电话给openOptionsMenu任何其他方式后,将显示活动,而无需使用这样的事情:
新的处理程序()。postDelayed(新的Runnable(){ 公共无效的run(){ openOptionsMenu(); } },1000);
参考: <一href="http://groups.google.com/group/android-beginners/browse_frm/thread/b10a8ea840c07725/1ce48bb147a3ed1a?#1ce48bb147a3ed1a">http://groups.google.com/group/android-beginners/browse_frm/thread/b10a8ea840c07725/1ce48bb147a3ed1a?#1ce48bb147a3ed1a
编辑:我AP preciate这样的例子:
公共无效的onCreate(包savedInstanceState){ super.onCreate(savedInstanceState); //现在我想是这样Window.Callback.onAttachedToWindow(...)应该做些什么呢? }
我看着活动
再次,它已经有方法<一href="http://developer.android.com/reference/android/app/Activity.html#onAttachedToWindow%28%29">onAttachedToWindow,从<一个继承href="http://developer.android.com/reference/android/view/Window.Callback.html#onAttachedToWindow%28%29">Window.Callback,由于API级别5.如果您使用的是这个水平,那么你只需要在你的活动
覆盖此方法。
@覆盖
公共无效onAttachedToWindow(){
super.onAttachedToWindow();
openOptionsMenu();
}
如果您使用的是之前的版本为5,那么你必须重写<一href="http://developer.android.com/reference/android/view/View.html#onAttachedToWindow%28%29">onAttachedToWindow在查看的方法来代替。这是很容易的,如果你的查看
在code创建。如果是在XML中创建的,那么它是不是更难 - 你应该在这里找到说明有帮助的。
Is there any other way to call openOptionsMenu after activity is displayed without using something like this:
new Handler().postDelayed(new Runnable() { public void run() { openOptionsMenu(); } }, 1000);
EDIT: I would appreciate example like this:
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Now I guess something like Window.Callback.onAttachedToWindow(...) should be done? }
I looked at Activity
again, and it has had the method onAttachedToWindow, inherited from Window.Callback, since API level 5. If you are using this level, then you simply have to override this method in your Activity
.
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
openOptionsMenu();
}
If you are using a version prior to 5, then you have to override the onAttachedToWindow method in View instead. This is very easy if your View
is created in code. If it is created in XMl, then it isn't that much harder - you should find the instructions here helpful.
这篇关于Android的 - openOptionsMenu中不起作用的onCreate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!