How change position of popup menu on android overflow button?

后端 未结 5 2141
再見小時候
再見小時候 2020-12-06 01:46

I just like to implement somethings same as popup menu in the Gmail app, anchored to the overflow button at the top-right. for that I used the same code as google tutorial f

5条回答
  •  暖寄归人
    2020-12-06 02:37

    Add the following piece of code to your activity:

    PopupWindow popupwindow_obj; // create object
    
    popupwindow_obj=popupDisplay();  // initialize in onCreate()
    
    popupwindow_obj.showAsDropDown(clickbtn,-40, 18); // where u want show on view click event
    
    public PopupWindow popupDisplay() { // disply designing your popoup window
        final PopupWindow popupWindow = new PopupWindow(this); // inflet your layout or diynamic add view
    
        View view; 
    
        LayoutInflater inflater = (LayoutInflater)   getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    
        view = inflater.inflate(R.layout.mylayout, null);
    
        Button item = (LinearLayout) view.findViewById(R.id.button1);
    
        popupWindow.setFocusable(true);
        popupWindow.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
        popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
        popupWindow.setContentView(view);
    
        return popupWindow;
    }
    

    Create an XML in res/layout directory and name it mylayout.xml

    
    
            

提交回复
热议问题