眼前多少难甘事,自古男儿当自强。这篇文章主要讲述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; } } }; }
【Android封装类似微信的顶部TitleBar弹出的PopupWindow代码】剩余封装好的工具类不贴了,还有图片啊,颜色啊资源文件,我把demo上传到了CSDN资源下载,下载地址请点击:
PopupWindow示例
推荐阅读
- HTML5 Plus移动App(5+App)开发入门指南
- POJ 2385 Apple Catching
- Android View 上下左右四种间距的设置方法
- Android ScrollView 滚动到顶部
- Android RecyclerView 设置item间隔的方法
- HOJ13907Diana and the Golden Apples
- Android开发基本环境搭建
- jmeter测试APP时如何录制脚本
- JSP中的登录和注销示例