RuntimeException: Binary XML file line #17: You must supply a layout_height attribute whie showing the popupmenu

后端 未结 4 341
遥遥无期
遥遥无期 2021-01-13 06:30
        public void showPopup(int group,int img_index,JSONArray json_ar,View v){

        PopupMenu pm=new PopupMenu(EditPhotosActivity.this,v);
        pm.getMenuIn         


        
相关标签:
4条回答
  • 2021-01-13 07:11

    Although I was using AppCompat Theme, but I still had the same problem

    I found out that problem is in the declaration of the PopupMenu, and the context I am passing to it.

    I was using it like that:

    PopupMenu popup = new PopupMenu(getApplicationContext(),v)
    

    But it should be like this:

     PopupMenu popup = new PopupMenu(MyActivity.this,v)
    
    0 讨论(0)
  • 2021-01-13 07:13

    I think this might be happening because you are using getBaseContext() at Toast.makeText . Try using getApplictaionContext() or EditPhotosActivity.this

    0 讨论(0)
  • 2021-01-13 07:20

    Make sure your have set right theme. android.support.v7.widget.PopupMenu expect the Application to have AppCompat theme, else it will throw exception when you try to show the PopupMenu

     android:theme="@style/Theme.AppCompat"
    

    But, android.widget.PopupMenu will work without this theme.

    0 讨论(0)
  • 2021-01-13 07:23

    I had the same issue when creating PopupMenu. I determined that PopupMenu was using:

    import android.support.v7.widget.PopupMenu;
    

    The fix was to edit it to:

    import android.widget.PopupMenu;
    
    0 讨论(0)
提交回复
热议问题