In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces Android how to achieve long-press pop-up PopupMenu menu bar, the article is very detailed, has a certain reference value, interested friends must read it!
A special menu effect has been added to the SDK3.0 version of Android, which can be displayed on any View, depending on the location of the View.
Res/menu/menu.xml
MainActivity.java
Package com.zhangyu.mypopupmenu;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.MenuItem;import android.view.View;import android.widget.PopupMenu;import android.widget.TextView;import android.widget.Toast;public class MainActivity extends AppCompatActivity {private TextView tv1; private TextView tv2; private TextView tv3; @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); initView () } private void initView () {tv1 = (TextView) findViewById (R.id.tv1); tv2 = (TextView) findViewById (R.id.tv2); tv3 = (TextView) findViewById (R.id.tv3); tv1.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {myPopupMenu (v);}}); tv2.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {myPopupMenu (v);}}) Tv3.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {myPopupMenu (v);}});} private void myPopupMenu (View v) {/ / define PopupMenu object PopupMenu popupMenu = new PopupMenu (MainActivity.this, v); / / set the layout of PopupMenu object popupMenu.getMenuInflater () .inflate (R.menu.menu, popupMenu.getMenu ()) / / set PopupMenu click event popupMenu.setOnMenuItemClickListener (new PopupMenu.OnMenuItemClickListener () {@ Override public boolean onMenuItemClick (MenuItem item) {Toast.makeText (MainActivity.this, "clicked--" + item.getTitle (), Toast.LENGTH_SHORT). Show (); return true;}}); / / display menu popupMenu.show ();}}
The above is all the contents of the article "how to long press and pop up the PopupMenu menu bar in Android". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.