Skip to content

Instantly share code, notes, and snippets.

@gabrielemariotti
Created August 4, 2014 13:22
Show Gist options
  • Save gabrielemariotti/ae63392e1c70bc33af8b to your computer and use it in GitHub Desktop.
Save gabrielemariotti/ae63392e1c70bc33af8b to your computer and use it in GitHub Desktop.
Android-L: A little example of the new Toolbar view.
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>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="example.gmariotti.it.test21.ToolbarActivity" >
<item android:id="@+id/action_search"
android:title="@string/action_search"
android:icon="@drawable/ic_search"
android:showAsAction="ifRoom" />
<item android:id="@+id/action_share"
android:title="@string/action_share"
android:icon="@drawable/ic_share"
android:showAsAction="ifRoom" />
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:orderInCategory="100"
android:showAsAction="never" />
</menu>
@ebrirad
Copy link

ebrirad commented Mar 18, 2017

very good bro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment