如何使用ListPopupWindow實現類似這樣的事情?工具欄上的複雜菜單項
我試圖讓onOptionsItemSelected項目視圖實例,因此而在onCreateOptionsMenu它返回null(正如你所看到的註釋行):
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.menu_socials, menu); // The line bellow was returning null
// ImageButton view = (ImageButton) menu.findItem(R.id.fake_overflow).getActionView();
listPopupWindow = new ListPopupWindow(
getContext());
listPopupWindow.setAdapter(new ArrayAdapter(
getContext(),
android.R.layout.simple_expandable_list_item_1, products));
listPopupWindow.setWidth(300);
listPopupWindow.setHeight(400);
listPopupWindow.setModal(true);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
View view = getActivity().findViewById(R.id.fake_overflow);
// listPopupWindow.show();
listPopupWindow.setAnchorView(view);
listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.i("TAG","action click?");
listPopupWindow.dismiss();
}
});
return super.onOptionsItemSelected(item);
}
的錨點視圖您可以嘗試創建自定義彈出菜單 – Aayushi
其新的溢出菜單在新的支持lib appcompat-v7中的新外觀。 – Mahalakshmi