I am trying to add ActionBar to my android activity, but app automatically closes due to some code error. So what is the proper code to display ActionBar in the Activity?
I tried this code in onCreate method but its not working
ActionBar actionBar;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.timetable);
actionBar = getActionBar();
actionBar.setTitle("MY TITLE");
actionBar.show();
}
Following code:
Try this,
ActionBar
useToolbar
.AppCompatActivity
instead ofActionBarActivity
.getSupportActionBar()
instead ofgetActionBar()
.Toolbar
is shown by default, so you dont nedd to call theshow()
method.Android Toolbar Example