zoukankan      html  css  js  c++  java
  • Android封装类似微信的顶部TitleBar弹出的PopupWindow代码

    Android仿微信顶部titlebar,点击加号弹出的PopupWindow,是封装好的PopupWindow,直接拿来用即可,先看效果图: 
    这里写图片描述 
    调用代码非常简单,这是MainActivity的代码:

    public class MainActivity extends AppCompatActivity {
        private TitlePopup titlePopup;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            initPopWindow();
            findViewById(R.id.bt_start).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    titlePopup.show(v);
                }
            });
        }
        private void initPopWindow() {
            // 实例化标题栏弹窗
            titlePopup = new TitlePopup(this, ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            titlePopup.setItemOnClickListener(onitemClick);
            // 给标题栏弹窗添加子类
            titlePopup.addAction(new ActionItem(this, R.string.menu_groupchat,
                    R.drawable.icon_menu_group));
            titlePopup.addAction(new ActionItem(this, R.string.menu_addfriend,
                    R.drawable.icon_menu_addfriend));
            titlePopup.addAction(new ActionItem(this, R.string.menu_qrcode,
                    R.drawable.icon_menu_sao));
            titlePopup.addAction(new ActionItem(this, R.string.menu_money,
                    R.drawable.abv));
        }
    
        private TitlePopup.OnItemOnClickListener onitemClick = new TitlePopup.OnItemOnClickListener() {
    
            @Override
            public void onItemClick(ActionItem item, int position) {
                // mLoadingDialog.show();
                switch (position) {
                    case 0:// 发起群聊
                        Toast.makeText(getApplicationContext(), "发起群聊", Toast.LENGTH_SHORT).show();
                        break;
                    case 1:// 添加朋友
                        Toast.makeText(getApplicationContext(), "添加朋友", Toast.LENGTH_SHORT).show();
                        break;
                    case 2:// 扫一扫
                        Toast.makeText(getApplicationContext(), "扫一扫", Toast.LENGTH_SHORT).show();
                        break;
                    case 3:// 收钱
                        Toast.makeText(getApplicationContext(), "收钱", Toast.LENGTH_SHORT).show();
                        break;
                    default:
                        break;
                }
            }
        };
    }

    剩余封装好的工具类不贴了,还有图片啊,颜色啊资源文件,我把demo上传到了CSDN资源下载,下载地址请点击: 
    PopupWindow示例

  • 相关阅读:
    HashMap源码分析
    LinkedList源码分析
    ArrayList源码学习
    Java容器知识总结
    Collections 工具类和 Arrays 工具类常见方法
    Java基础知识
    MySQL高级之索引优化分析
    MySQL命令大全
    Java IO
    SpringCloud笔记
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/7436691.html
Copyright © 2011-2022 走看看