I have simple application.
Here is MyActivity.java
public class MyActivity extends Activity {
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return super.onCreateOptionsMenu(menu);
}
}
And I don't really understand why method onCreateOptionsMenu
is called on phone and is not called on tablet?
If you're using ToolBar:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
mToolbar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(mToolbar);
}
there is concept called ActionBar from API 11, so option menu is not use for tablet version.
check for ActionBar tutorial.. see below link
如果您的活动是从Activity类扩展,请尝试将其更改为AppCompatActivity。
在OnCreateView(..)
您需要添加
setHasOptionsMenu(true);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.