1. 程式人生 > >Android封裝類似微信的頂部TitleBar彈出的PopupWindow代碼

Android封裝類似微信的頂部TitleBar彈出的PopupWindow代碼

彈出 調用 pro con and switch nload csdn 實例化

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代碼