mercredi 13 mai 2015

How can I stylize my menuPopup to look like the menu popup for powering down?

I have used menuPopups briefly before, but I've never figured out how to stylize them. I would like my menuPopup below, to look like this screenshot of the android power down menuPopup below

The features of the menu popup below to which I would like mine to posses (but so far I don't know how) are:

  • For a line to be placed between each row
  • To place an image, along side line of text
  • For square (menu popup) to be placed within center of screen (not just next to button)
  • To modify font type, size and color of each line of text

My code so far:

activity_main.class

final TextView textView2 = (TextView) findViewById(R.id.textView2);
        textView2.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                //Creating the instance of PopupMenu
                PopupMenu popup = new PopupMenu(MainActivity.this, textView2);
                //Inflating the Popup using xml file
                popup.getMenuInflater().inflate(R.menu.popup_menu, popup.getMenu());

                //registering popup with OnMenuItemClickListener
                popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                    public boolean onMenuItemClick(MenuItem item) {
                        Toast.makeText(MainActivity.this, "You Clicked : " + item.getTitle(), Toast.LENGTH_SHORT).show();
                        return true;
                    }
                });

                popup.show();//showing popup menu
            }
        });//closing the setOnClickListener method
    }

popup_menu.xml

<menu xmlns:android="http://ift.tt/nIICcg">
    <group android:id="@+id/group_popupmenu">
        <item android:id="@+id/menu1"
            android:title="Popup menu item 1"/>
        <item android:id="@+id/menu2"
            android:title="Popup menu item 2"/>
        <item android:id="@+id/menu3"
            android:title="Popup menu item 3"/>
    </group>
</menu>

Screenshot of powering down popup:

enter image description here

Screenshot of menu popup so far:

enter image description here

Aucun commentaire:

Enregistrer un commentaire