How can I create App bars (Action bar) like displayed on this screenshot? And how can I attach App bar to any view or card view? And is it possible with Android L SDK?
Asked
Active
Viewed 1,972 times
2 Answers
1
Take a look at article Action Bar simplification and Toolbar. Seems like you should use new Toolbar widget instead of ActionBar. Also here answer on stack

Community
- 1
- 1

Ivan Vazhnov
- 1,291
- 11
- 9
1
It is the new Toolbar widget.
Currenty this widget is supported only on Android-L.
You can put it in the xml layout:
<CardView>
<Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="56dp">
</Toolbar>
</CardView>
Then you can get it in your java code, with something like this:
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
//Title and subtitle
toolbar.setTitle("MY toolbar");
toolbar.setSubtitle("Subtitle");
//Menu
toolbar.inflateMenu(R.menu.toolbar_menu);
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
switch (menuItem.getItemId()){
case R.id.action_share:
Toast.makeText(ToolbarActivity.this,"Share",Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
});

Gabriele Mariotti
- 320,139
- 94
- 887
- 841