Skip to content

Instantly share code, notes, and snippets.

@ruan65
Created July 30, 2016 09:30
Show Gist options
  • Save ruan65/eae8c604f5dbe228a5965669ffe5ca49 to your computer and use it in GitHub Desktop.
Save ruan65/eae8c604f5dbe228a5965669ffe5ca49 to your computer and use it in GitHub Desktop.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.register, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_cancel:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<item
android:id="@+id/action_cancel"
android:orderInCategory="100"
android:title="Cancel"
android:icon="@drawable/ic_clear_white_24dp"
app:showAsAction="always"
/>
</menu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment