Position, Shadow and dismissing of PopupWindow like an Actionbar Menu [Android]
NickName:dinbrca Ask DateTime:2013-10-12T22:22:04

Position, Shadow and dismissing of PopupWindow like an Actionbar Menu [Android]

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: enter image description here

Currently - I have 3 problems:

  1. I need to position the menu to the right Actionbar button, and below it. like the usual Menus..

  2. 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)

  3. 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

More about “Position, Shadow and dismissing of PopupWindow like an Actionbar Menu [Android]” related questions

Position, Shadow and dismissing of PopupWindow like an Actionbar Menu [Android]

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:

Show Detail

Android Popup Menu Shadow

I created this popup menu but the background shadow is missing. How can I add some? It would be cool if the shadow is only on the left and the bottom. Here is a picture: You can see that the color...

Show Detail

android PopupWindow not open from custom actionbar

NewChatThroughNotification extends BaseActivity super.onCreate(savedInstanceState); /* setContentView(R.layout.notification_chat); */ setContentView(R.layout.activitychat); setUpAct...

Show Detail

Remove shadow in Android PopupWindow

I have created my PopupWindow using a simple LinearLayout with a background color. There is a shadow on the PopupWindow. How do I remove the shadow automatically generated for the PopupWindow. I

Show Detail

Android PopupWindow not changing position after calling update()

My Android app has a game map with markers on it. When the user taps a marker, I'm displaying a PopupWindow aligned with the map marker (similar to Google Maps). The problem I'm having is if a mar...

Show Detail

Android ClickListeners not firing from a PopupWindow

I've got a popupWindow that is triggered from the Activity Bar in Main Event. The buttons in the popup window are not triggering their respective listeners in showPopup(). Much of this popupWindow

Show Detail

Android PopupWindow: White background but keep shadow?

How do I style my PopupWindow in Android with a white background but still keep the shadow? I am trying to create something like [this][1]: By default, my PopupWindow has a dark background. So I s...

Show Detail

How to change the position of menu items on actionbar

I'm developing one application in which I have to add a custom layout on actionbar. Adding the custom layout is done, but when I'm adding the menu items on actionbar my custom layout changes it's

Show Detail

Can I get the position of the overflow menu and any other menu in the Action Bar

I have a ActionBar setup in my AppCompatActivity and I would very much like to be ablt to get the position of the menu items and the overflow menu, so that I can have a tool tip pointing to any ite...

Show Detail

Android ActionBar with Sliding Tabs - how to remove the shadow effects

I have created a screen which has an ActionBar and three sliding tabs. I want to have the ActionBar and the sliding tabs to have the same color and not have any demarcation between them. But the tabs

Show Detail