我的布局文件夹中有一个 LinearLayout,名为“settings_caching_popup.xml”,我试图在onOptionsItemSelected(MenuItem item)显示弹出窗口的方法中使用此布局。但findViewById(R.layout.settings_caching_popup)总是返回 null。然后我在 xml 布局中将一个 ID 设置为 LinearLayoutandroid:id="@+id/settings_caching_popup并调用findViewById(R.id.settings_caching_popup). 返回也为空。
拉出onOptionsItemSelected(MenuItem item):
PopupWindow popUp = new PopupWindow(context);
LinearLayout ll = (LinearLayout) findViewById(R.layout.settings_caching_popup);
popUp.setContentView(ll);
popUp.showAtLocation(ll, Gravity.BOTTOM, 10, 10);
popUp.update(50, 50, 300, 80);