Answer the question
In order to leave comments, you need to log in
How to add item item to menu in android?
I am new to this I have 2 questions:
1. I have a standard code
<item android:id="@+id/nav_favorites"
android:title="@string/favorites">
<menu android:id="@+id/nav_favorites_main">
<item
android:id="@+id/nav_share"
android:title="Share" />
</menu>
</item>
Answer the question
In order to leave comments, you need to log in
one.
Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.add(Menu.NONE, nav_share, Menu.NONE, "Share");
super.onCreateOptionsMenu(menu, inflater);
}
public class MyFragment extends Fragment {
private Menu menu;
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
this.menu = menu;
super.onCreateOptionsMenu(menu, inflater);
}
private void updateTitle () {
MenuItem shareItem = menu.findItem(R.id.share);
shareItem.setTitle("Поделиться");
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question