/res/menu/option_menu.xml
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android"> <item android:title="@string/search" android:icon="@drawable/ic_search_white_24dp" app:showAsAction="ifRoom"/> <item android:title="@string/share" android:icon="@drawable/ic_share_white_24dp" /> </menu>
MainActivity.java
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.option_menu,menu); return super.onCreateOptionsMenu(menu); } }
References
https://github.com/mhdr/AndroidSamples/tree/master/020