-
-
Save gabrielemariotti/ae63392e1c70bc33af8b to your computer and use it in GitHub Desktop.
| 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; | |
| } | |
| }); | |
| //Navigation Icon | |
| toolbar.setNavigationIcon(R.drawable.ic_launcher); | |
| toolbar.setNavigationOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View view) { | |
| Toast.makeText(ToolbarActivity.this,"Navigation",Toast.LENGTH_SHORT).show(); | |
| } | |
| }); |
| <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| android:orientation="vertical" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent"> | |
| <Toolbar | |
| android:id="@+id/toolbar" | |
| android:layout_width="match_parent" | |
| android:layout_height="56dp"> | |
| </Toolbar> | |
| <View | |
| android:layout_width="match_parent" | |
| android:layout_height="1dp" | |
| android:background="@color/gray"/> | |
| </LinearLayout> |
Nice, how do you set the navigation icon in xml?
any screenshots?
@yelinaung You can use the new ToolBar for greater flexibility:
http://developer.android.com/reference/android/widget/Toolbar.html
http://developer.android.com/reference/android/support/v7/widget/Toolbar.html
@cforlife
android:navigationIcon
@siddharth96
http://antonioleiva.com/material-design-everywhere/
It would be good to show how navdrawer works too
@bamsbamx +1
HOW TO MAKE TOOLBAR TRANSPARENT
<style name="ToolbarTheme" parent="Theme.AppCompat">
<item name="android:background">**your color**</item>
</style>
and then use it like this in layout
<Toolbar
...
app:theme="@style/ToolbarTheme"/>
I am exploring the Toolbar. I don't find a way to define android.support.v7.widget.Toolbar using XML completely. What I mean by this is that the toolbar components such as title, subtitle need to added through code but not using XML. Is there a way to add these components using XML? If not, why toolbar is designed like this?
very good bro
It looks a lot like new ActionBar ? Or is it the ActionBar ? 😕