In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about how Android in Java adds menu items to Textview. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
Background description:
There is a Textview and a Button on the interface, and when we click Textview, a menu pops up, then we select an option, and when we finally click the button, we execute the corresponding function according to the selected menu item.
Solution.
There are three steps in total:
1. First create the menu folder under the res folder, and then create the menu file main.xml
two。 To add a menu to Activity, and how to add it, first define the menu button PopupMenu, and then override the menu listening event
3. Finally, give the control that needs the pop-up menu (such as adding the property android:onClick= "menuClick" to Textview)
Specific steps: 1. Create a menu file
two。 Add menus to activity and override menu listening events
Create pop-up menu variabl
Private PopupMenu popupMenu;// definition menu button
Override menu monitoring events
/ / rewrite menu listening event public void menuClick (View view) {popupMenu = new PopupMenu (this,view); getMenuInflater () .inflate (R.menu.mainjold popupMenu.getMenu ()) PopupMenu.setOnMenuItemClickListener (new PopupMenu.OnMenuItemClickListener () {@ Override public boolean onMenuItemClick (MenuItem item) {switch (item.getItemId ()) {case R.id.to_detail: flag.setText ("detail enhancement"); break Case R.id.to_fudiao: flag.setText ("embossed effect"); break; case R.id.to_mosic: flag.setText ("mosaic"); break Case R.id.to_frost: flag.setText ("dot"); break; case R.id.to_spread: flag.setText ("ground glass"); break;} return true ); popupMenu.show ();} 3. Add menu response properties to the control
What are the collection classes in Java? the sets in Java are mainly divided into four categories: 1, List list: ordered, repeatable; 2, Queue queue: ordered, repeatable; 3, Set collection: non-repeatable; 4, Map mapping: disorder, key unique, value is not unique.
After reading the above, do you have any further understanding of how Android adds menu items to Textview in Java? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.