[:en]
Step 1: menu_second_page.xml
Step 2. SecondPage.java
package com.cambridgeways.com.toolbardemo; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; // Very important import below: import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.Toast; public class SecondPage extends AppCompatActivity { private Toolbar toolbar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second_page); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); if (getSupportActionBar() != null){ getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setDisplayShowTitleEnabled(false); getSupportActionBar().setLogo(R.mipmap.ic_launcher); getSupportActionBar().setDisplayUseLogoEnabled(true); } toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(SecondPage.this, MainActivity.class)); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_second_page, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will switch (item.getItemId()) { case R.id.action_search: Toast.makeText(getApplication(), "Search shown", Toast.LENGTH_LONG).show(); return true; case R.id.action_user: Toast.makeText(getApplication(), "Settings shown", Toast.LENGTH_LONG).show(); return true; case R.id.action_fast: Toast.makeText(getApplication(), "Fast shown", Toast.LENGTH_LONG).show(); return true; case R.id.action_add: Toast.makeText(getApplication(), "Add shown", Toast.LENGTH_LONG).show(); return true; default: return super.onOptionsItemSelected(item); } }
Step 3: toolbar.xml
Step 4: colors.xml
#F44336 #D32F2F #FFCDD2 #03A9F4 #212121 #727272 #Ffffff
Link to get android official icons free download
https://design.google.com/icons/index.html#ic_search
[:]