【发布时间】:2016-03-18 05:52:09
【问题描述】:
我正在尝试将 ActionBar 添加到我的 android 活动中,但由于某些代码错误,应用程序会自动关闭。那么在 Activity 中显示 ActionBar 的正确代码是什么?
我在 onCreate 方法中尝试了这段代码,但它不起作用
ActionBar actionBar;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.timetable);
actionBar = getActionBar();
actionBar.setTitle("MY TITLE");
actionBar.show();
}
【问题讨论】:
-
请发布详细的错误信息。
-
欢迎来到 StackOverflow!请参阅:How to create a Minimal, Complete, and Verifiable example,并尝试按照这些指南添加更多信息,以吸引更多对您的问题的积极关注。
-
它在 actionBar.show() 上显示错误; @JohnnyShieh
-
它在 actionBar.show() 上显示错误; @MeetTitan
-
getActionBar() => getSupportActionBar 并使用 Theme has ActionBar
标签: android android-activity android-actionbar