Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to imitate Wechat and qq by clicking the plus sign pop-up action box in the upper right corner of Android?

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

In this article Xiaobian for everyone to introduce in detail "Android how to achieve imitation Wechat and qq click on the upper right corner of the pop-up operation box", detailed content, clear steps, details handled properly, I hope that this "Android how to achieve imitation Wechat and qq click on the upper right corner of the pop-up operation box" article can help you solve doubts, following the editor's ideas slowly in-depth, together to learn new knowledge bar.

Android imitates Wechat and qq clicks the plus sign in the upper right corner to pop up the action box. The image above is similar to the one below. Clicking the plus sign will bring up a dialog box, as shown below:

Wechat:

Implement on your own:

Next, let's implement this feature:

In fact, the principle of implementation is to click on the "+" sign and pop up a PopupWindow.

1. Write a menu file to be displayed in ToolBar, as follows:

2. Add "+" first. ToolBar is used in my project. I add a menu to ToolBar and rewrite the method onCreateOptionsMenu in Activity, as shown below:

@ Override public boolean onCreateOptionsMenu (Menu menu) {getMenuInflater () .inflate (R.menu.menu_index_msg, menu); return super.onCreateOptionsMenu (menu);}

At this point, the "+" sign has appeared.

3. Add a click event to the menu, initialize the PopupWindow, and pop up the custom PopupWindow, as follows:

@ Override public boolean onOptionsItemSelected (MenuItem item) {switch (item.getItemId ()) {case R.id.btn_msg: View popupView = IndexActivity.this.getLayoutInflater () .inflate (R.layout.popupwindow, null); final PopupWindow window = new PopupWindow (popupView, 300,220); ListView lv_msg = (ListView) popupView.findViewById (R.id.lv_msg); MsgAdapter msgAdapter = new MsgAdapter (context, msgBeans); lv_msg.setAdapter (msgAdapter) Lv_msg.setOnItemClickListener (new AdapterView.OnItemClickListener () {@ Override public void onItemClick (AdapterView parent, View view, int position, long id) {if (window.isShowing ()) {window.dismiss () } switch (position) {case 0: if (myApplication.isOnline ()) {NoticeMainActivity.startActivity (IndexActivity.this);} else {Toast.makeText (IndexActivity.this, "this feature is not available offline", Toast.LENGTH_SHORT) .show () } break; case 1: if (myApplication.isOnline ()) {TaskMainActivity.startActivity (IndexActivity.this);} else {Toast.makeText (IndexActivity.this, "this feature is not available offline", Toast.LENGTH_SHORT) .show () } break; default: break;}); window.setBackgroundDrawable (new ColorDrawable (Color.parseColor ("# F8F8F8"); window.setFocusable (true); window.setOutsideTouchable (true); window.update () / / set the display position window.showAsDropDown (msgView, 0,0); / / msgView is the btn_msg break; default in our menu: break;} return super.onOptionsItemSelected (item);}

4. In the above 3, there is a layout popupwindow, which displays notifications when it is used in my project. I use ListView to display content in the layout. You can also write the layout as a fixed layout and give full play to it according to your own needs. The popupwindow layout is posted below, as follows:

5. At this point, we have achieved the function we want, and the result diagram:

6. Notification and the number of messages displayed on the right side of the task are constrained by the shape xml file, or you can use BadgeView to achieve, which is not explained too much here.

Read here, the "Android how to achieve imitation Wechat and qq click on the upper right corner plus pop-up operation box" article has been introduced, want to master the knowledge of this article also need to practice and use in order to understand, if you want to know more about the article, welcome to pay attention to 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: 261

*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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report