Leila Farias
Posted on September 18, 2021
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);
}
}
Referências
💖 💪 🙅 🚩
Leila Farias
Posted on September 18, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
undefined A Comprehensive Guide to React Native: Building Cross-Platform Apps with Ease
November 20, 2024