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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
very good bro