I am trying to create a PopupWindow that works like an Actionbar Menu like in Chrome for android -
example:
How to create custom sub menu like Google Chrome application
Here's what I have so far:
Currently - I have 3 problems:
I need to position the menu to the right Actionbar button, and below it. like the usual Menus..
I need to have a shadow on the PopupWindow (for some reason it is removed, as I know PopupWindow automatically have this shadow around it)
When clicking outside the PopupWindow, I need it to dismiss like the usual menus of the Actionbar..
Here's my code-
On click of the Actionbar button this is the code that runs:
LayoutInflater inflater = (LayoutInflater) MainActivity.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final PopupWindow pw = new PopupWindow(inflater.inflate(
R.layout.options_menu, null, false), LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, true);
pw.showAtLocation(findViewById(R.id.main_cont), Gravity.NO_GRAVITY, 50, this.getSupportActionBar().getHeight() + 1);
ListView moreOptions = (ListView)pw.getContentView().findViewById(R.id.moreOptions);
String[] options = new String[] { "Settings", "Feedback", "Contribute", "DashClock Integration", "Tutorial", "ViewPager Demo", "Expandable List Demo", "Change Language", "Add 5 to list", "Add 20 to list" };
final ArrayList<String> moreOptionsList = new ArrayList<String>();
for (int i = 0; i < options.length; ++i) {
moreOptionsList.add(options[i]);
}
ArrayAdapter<String> moreOptionsAdapter=new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
moreOptionsList);
moreOptions.setAdapter(moreOptionsAdapter);
//pw.setBackgroundDrawable(this.getResources().getDrawable(R.drawable.listview_bg_inverted));
/*
pw.setTouchable(true);
pw.setFocusable(false);
*/
pw.setOutsideTouchable(true);
Design of the menu:
http://pastebin.com/yi6S2HDt
Thanks in advanced,
Din.
Copyright Notice:Content Author:「dinbrca」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/19335208/position-shadow-and-dismissing-of-popupwindow-like-an-actionbar-menu-android