Created
August 4, 2014 13:22
-
-
Save gabrielemariotti/ae63392e1c70bc33af8b to your computer and use it in GitHub Desktop.
Android-L: A little example of the new Toolbar view.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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/