Android popupmenu position -
I'm trying to create an Android app where clicking on a button raises the popup menu The popup menu is being generated but not on the right position. The code is as follows:
menu.xml
& lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Menu xmlns: Android = "http://schemas.android.com/apk/res/android" & gt; & Lt; Group Android: checkable browser = "single" & gt; & Lt; Item Android: id = "@ + ID / Lingmail" Android: Title = "Male" /> & Lt; Android Android: id = "@ + id / genderFemale" Android: title = "female" /> & Lt; / Groups & gt; & Lt; / Menu & gt; Function to perform a popup is as follows:
Public Zero Show Genderpop (see V) {popup menu popup = new popup menu (This, V) ; MenuInflater inflater = popup.getMenuInflater (); Inflater.inflate (rn menu, gender_popup, popup.getMenu ()); Popup.show (); } Here the popup menu is being created under textview when I click it. I want to generate it at the center of the screen.
How about it?
is written with the docs:
A popup menu on a view A model of anchor displays a menu in the popup window. The popup anchor will appear below the view if there is no room, or not above it. If IME is visible, the popup will not overlap it until it has touched. Touching out of the popup, it will be rejected.
As I think, "see v"
public zero show GenderPopup (see V) You are clickable textvouw, which is linked to the method when it is clicked, which means that the popup menu will show just below the textview.
Will not you achieve your goal with a dialogue? Before you create a dialog for a custom alert dialog, you need to use Alert Dialog.builder's method
setView (see V) .
To view your custom, you must either follow two methods:
XML: Create your XML layout file and then see the implementation of XML layout on a custom custom object object. for. (Layout file is called customDialog.xml as an example)
LayoutsInfliler Inflar = (LayoutInflator) Reference. Gate system system (reference. LEOUT_INFLATER_SERVICE); View customView = inflater.inflate (R.layout.customDialog, null); Radiobutan Radiobutan = (Radiobutton) Customview.FindVBIID (RIDCostiDiologRadiButton); Radiobuten. SethOneClicklist (New OnListList () {.}); Mobility:
I will use LinearLayout as an example.
LinearLayout customview = new linerlayout (reference); Radiobutan radiobetien = new radio button (reference); Radio BTN.SetOneClicklist (new OnListList () {..}); CustomView.addView (radioBtn); You then use this code to create the dialog
AlertDialog.bilder B = new alertDialog.bilder (reference); B.setMessage ("Example"); // Set the parameters of dialog from Builder B.SetView (customview); Dialog D = B.Cert (); D.show ();
Comments
Post a Comment