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示例

  • 相关阅读:
    python之re(正则表达式)
    virtualbox之下载地址
    数据库之sqlite
    vmware 虚拟机扩展 liunx系统硬盘空间
    常见python面试题-手写代码系列
    Python的Struct模块
    mac上安装brew如何加速
    outlook数字证书导出、导入及解决老是弹出macOS需要访问系统钥匙串弹窗问题
    docker命令学习
    Message from syslogd不停的打日志
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/7436691.html
Copyright © 2011-2022 走看看