码迷,mamicode.com
首页 > 微信 > 详细

Android封装类似微信的顶部TitleBar弹出的PopupWindow代码

时间:2017-08-27 00:11:45      阅读:423      评论:0      收藏:0      [点我收藏+]

标签:hat   show   short   pup   undle   ppc   listener   blog   public   

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

Android封装类似微信的顶部TitleBar弹出的PopupWindow代码

标签:hat   show   short   pup   undle   ppc   listener   blog   public   

原文地址:http://www.cnblogs.com/zhujiabin/p/7436691.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!