Questions tagged «android-optionsmenu»

19
如何在Android中将选项菜单添加到片段
我正在尝试从一组片段中将一个项目添加到选项菜单。 我创建了一个新MenuFragment类,并将其扩展为希望包含菜单项的片段。这是代码: Java: public class MenuFragment extends Fragment { MenuItem fav; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); } public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { fav = menu.add("add"); fav.setIcon(R.drawable.btn_star_big_off); } } 科特林: class MenuFragment : Fragment { lateinit var fav: MenuItem override fun onCreate(savedInstanceState: Bundle) { super.onCreate(savedInstanceState) setHasOptionsMenu(true) …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.