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

限于喜欢 提交于 2019-12-01 05:55:37

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.

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)
NguyenNguyen

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;

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!