I am new to android and i was following following tutorial for Material Design Toolbar :
http://www.android4devs.com/2014/12/how-to-make-material-design-app.
You need to call setContentView
BEFORE adding any View
s such as the Toolbar
.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); // <-- call this first
toolbar = (Toolbar) findViewById(R.id.toolbar); // <-- setup views after
setSupportActionBar(toolbar);
setTitle("DDIT_Results");
}
Please see the Official Android Developers blog here: http://android-developers.blogspot.com/2014/10/appcompat-v21-material-design-for-pre.html
To use Toolbar as an Action Bar, first disable the decor-provided Action Bar. The easiest way is to have your theme extend from Theme.AppCompat.NoActionBar (or its light variant).
Second, create a Toolbar instance, usually via your layout XML:
The height, width, background, and so on are totally up to you; these are just good examples. As Toolbar is just a ViewGroup, you can style and position it however you want.
Then in your Activity or Fragment, set the Toolbar to act as your Action Bar:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.blah);
final Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);
}
From this point on, all menu items are displayed in your Toolbar, populated via the standard options menu callbacks.