Tutorial pá-pum pra você criar menus de contexto no Android, usando Java:
Crie o resource file menu.xml na pasta 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:id="@+id/refresh_page"
android:title="Refresh"
app:showAsAction="always" />
</menu>
Adicione o menu à activity
java
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
Adicione ação aos botões do menu
java
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.refresh_page:
refreshPage();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Top comments (0)