Problem summary (5)-menu refresh

Source: Internet
Author: User

In a recent project, the menu icon was required to be dynamically replaced. Finally, I checked the information and finally got it done:

First, the onCreateOptionsMenu function will only be executed once. If you create a menu, you can only display the initialized menu content and cannot change its value dynamically. During the test, we found that onPrepareOptionsMenu will be executed every time you click the menu key, so the problem is solved. The onPrepareOptionsMenu parameter is also the menu, so we try to add the menu item here (first block the menu in onCreateOptionsMenu) to verify whether it can meet our expectations. The result is acceptable.

Note: to create a menu in onPrepareOptionsMenu, you must first set menu. clear (); otherwise, more and more will be added.

 

Author: agods

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.