@Override publicbooleanonCreateOptionsMenu(Menu menu){ // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); returntrue; }
@Override publicbooleanonOptionsItemSelected(MenuItem item){ // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if(id == R.id.action_settings){ returntrue; } returnsuper.onOptionsItemSelected(item); } }
Step 2:
Modify the theme in styles.xml file with AppCompat Theme in values folder
values/styles.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<resources>
<!-- Base application theme using AppCompatv21 Library --> <stylename="AppBaseTheme"parent="Theme.AppCompat.Light.DarkActionBar">
<!-- your app branding color for the app bar --> <itemname="colorPrimary">@color/md_blue_500_primary</item>
<!-- darker variant for the status bar and contextual app bars --> <itemname="colorPrimaryDark">@color/md_blue_700</item>
<!-- theme UI controls like checkboxes and text fields --> <itemname="colorAccent">@color/md_red_200</item> </style>