how to change margin between items in popupmenu
I want to change the space between items in my popupmenu on android
the space i mean is this one:
I hope there is a straight foward solution, but as i know android it shall not be so simple
anyway i would like also to set the maxHeight
of my popUp...
In this case popup is achored by the TextView "Select the prize" so it fills the space above it, but not all the items fit in that space so android automatically creates an scrow view (on vertical)
the thing is, I know 100% of users wont use this scroll so the items in my menu bellow "Travel" will never be seen.
How can i set the height in order to make enough space to all items?
=============UPDATE================
Just to make it clear, this isn't a spinner it is a popupmenu
this.popupCategories = new PopupMenu(this, this.categoryLabel);
for (Giveaway.GiveawayCategoryGroup catGroup : categoryGroups) {
SubMenu submenu = this.popupCategories.getMenu().addSubMenu(catGroup.getDescription(lang));
for (Giveaway.GiveawayCategory cat : (Collection<? extends Giveaway.GiveawayCategory>) catGroup.getCategories()) {
if (cat.isActive())
submenu.add(Menu.NONE, cat.getValue().hashCode(), (int) cat.getOrder(), cat.getDescription(lang));
}
}

add a comment |
I want to change the space between items in my popupmenu on android
the space i mean is this one:
I hope there is a straight foward solution, but as i know android it shall not be so simple
anyway i would like also to set the maxHeight
of my popUp...
In this case popup is achored by the TextView "Select the prize" so it fills the space above it, but not all the items fit in that space so android automatically creates an scrow view (on vertical)
the thing is, I know 100% of users wont use this scroll so the items in my menu bellow "Travel" will never be seen.
How can i set the height in order to make enough space to all items?
=============UPDATE================
Just to make it clear, this isn't a spinner it is a popupmenu
this.popupCategories = new PopupMenu(this, this.categoryLabel);
for (Giveaway.GiveawayCategoryGroup catGroup : categoryGroups) {
SubMenu submenu = this.popupCategories.getMenu().addSubMenu(catGroup.getDescription(lang));
for (Giveaway.GiveawayCategory cat : (Collection<? extends Giveaway.GiveawayCategory>) catGroup.getCategories()) {
if (cat.isActive())
submenu.add(Menu.NONE, cat.getValue().hashCode(), (int) cat.getOrder(), cat.getDescription(lang));
}
}

add a comment |
I want to change the space between items in my popupmenu on android
the space i mean is this one:
I hope there is a straight foward solution, but as i know android it shall not be so simple
anyway i would like also to set the maxHeight
of my popUp...
In this case popup is achored by the TextView "Select the prize" so it fills the space above it, but not all the items fit in that space so android automatically creates an scrow view (on vertical)
the thing is, I know 100% of users wont use this scroll so the items in my menu bellow "Travel" will never be seen.
How can i set the height in order to make enough space to all items?
=============UPDATE================
Just to make it clear, this isn't a spinner it is a popupmenu
this.popupCategories = new PopupMenu(this, this.categoryLabel);
for (Giveaway.GiveawayCategoryGroup catGroup : categoryGroups) {
SubMenu submenu = this.popupCategories.getMenu().addSubMenu(catGroup.getDescription(lang));
for (Giveaway.GiveawayCategory cat : (Collection<? extends Giveaway.GiveawayCategory>) catGroup.getCategories()) {
if (cat.isActive())
submenu.add(Menu.NONE, cat.getValue().hashCode(), (int) cat.getOrder(), cat.getDescription(lang));
}
}

I want to change the space between items in my popupmenu on android
the space i mean is this one:
I hope there is a straight foward solution, but as i know android it shall not be so simple
anyway i would like also to set the maxHeight
of my popUp...
In this case popup is achored by the TextView "Select the prize" so it fills the space above it, but not all the items fit in that space so android automatically creates an scrow view (on vertical)
the thing is, I know 100% of users wont use this scroll so the items in my menu bellow "Travel" will never be seen.
How can i set the height in order to make enough space to all items?
=============UPDATE================
Just to make it clear, this isn't a spinner it is a popupmenu
this.popupCategories = new PopupMenu(this, this.categoryLabel);
for (Giveaway.GiveawayCategoryGroup catGroup : categoryGroups) {
SubMenu submenu = this.popupCategories.getMenu().addSubMenu(catGroup.getDescription(lang));
for (Giveaway.GiveawayCategory cat : (Collection<? extends Giveaway.GiveawayCategory>) catGroup.getCategories()) {
if (cat.isActive())
submenu.add(Menu.NONE, cat.getValue().hashCode(), (int) cat.getOrder(), cat.getDescription(lang));
}
}


edited Jan 16 at 23:31
Rafael Lima
asked Jan 1 at 22:30
Rafael LimaRafael Lima
497418
497418
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
You need to set your preferred item row height in your AppTheme inside styles.xml
:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:listPreferredItemHeightSmall">20dp</item>
</style>
You may need to modify this number a bit to get the correct value, but it determines the height of those rows. Make sure to replace Theme.AppCompat.Light.DarkActionBar
with whatever you're currently using.
As for setting a maximum height, I'm afraid you'll have to create your own extension class for that, as in this example.
one extra question: when deal with those standard android styles... how can i know which one to override without trying a lots of them? ( i knew there was a styles for that but couldn't figure out which)
– Rafael Lima
Jan 30 at 3:19
1
Unfortunately, the answer is googling it or looking on Stack overflow. The answers can be found in the documentation, but it's usually pretty hard to find yourself.
– JakeSteam
Jan 30 at 7:13
add a comment |
PopupMenu
items are just regular MenuItem
; it's the same attribute, but another parent style:
<style name="customPopupMenuStyle" parent="@android:style/Widget.PopupMenu">
<item name="android:listPreferredItemHeightSmall">32dp</item>
</style>
this only affects the PopupMenu
to which the style had been assigned to.
also there one could set a custom ActionView
(per individual item, not as a template):
MenuItem item = menu.findItem(R.id.itemMenu);
MenuItemCompat.setActionView(item, R.layout.layout_menu);
this isn't a spinner... i added the code to make it clear
– Rafael Lima
Jan 16 at 23:27
@RafaelLima updated my answer accordingly.
– Martin Zeitler
Jan 19 at 10:15
add a comment |
You can create a layout for popup menu and initialize it in your activity as follows
XML
> <?xml version="1.0" encoding="utf-8"?> <LinearLayout
> xmlns:android="http://schemas.android.com/apk/res/android"
> android:layout_width="match_parent"
> android:layout_height="match_parent"
> android:gravity="center"
> android:background="@android:color/transparent">
> <LinearLayout
> android:layout_width="wrap_content"
> android:layout_height="YOUR MAX HEIGHT"
> android:gravity="center"
> android:weightsum="YOUR NUMBER OF ITEMS"
> android:orientation="vertical"
> android:layout_gravity="center"
> >
> <TextView
> android:layout_width="wrap_content"
> android:layout_height="0dp"
> android:weight="1" /> ...no of views items
> </LinearLayout> </LinearLayout>
INITIALIZE IT AS
View parentv = findViewById(R.id.activityview); //id of parent view of activity in which popup will be shown
LayoutInflater layoutInflater
= (LayoutInflater) getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.YOURPOPUPMENU, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.MATCH_PARENT);
TextView tv = popupView.findViewById(R.id.textviewid); //to do something with textview
tv.setText("Fashion");
popupWindow.setOutsideTouchable(true); //if you want to dismiss popup if clicked outside
popupWindow.setFocusable(true);
// Removes default background.
popupWindow.setBackgroundDrawable(new android.graphics.drawable.ColorDrawable(android.graphics.Color.TRANSPARENT));
// popupWindow.setAnimationStyle(R.style.righttoleftstyle); can put animation to slide in popupmenu by defining any animation
popupWindow.showAtLocation(parentv, Gravity.START | Gravity.TOP,0,0);
//will show popup on top left corner of the screen of the activity view you can try some iterations for it to show where on screen according to your needs
I hope it will help!
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53999449%2fhow-to-change-margin-between-items-in-popupmenu%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to set your preferred item row height in your AppTheme inside styles.xml
:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:listPreferredItemHeightSmall">20dp</item>
</style>
You may need to modify this number a bit to get the correct value, but it determines the height of those rows. Make sure to replace Theme.AppCompat.Light.DarkActionBar
with whatever you're currently using.
As for setting a maximum height, I'm afraid you'll have to create your own extension class for that, as in this example.
one extra question: when deal with those standard android styles... how can i know which one to override without trying a lots of them? ( i knew there was a styles for that but couldn't figure out which)
– Rafael Lima
Jan 30 at 3:19
1
Unfortunately, the answer is googling it or looking on Stack overflow. The answers can be found in the documentation, but it's usually pretty hard to find yourself.
– JakeSteam
Jan 30 at 7:13
add a comment |
You need to set your preferred item row height in your AppTheme inside styles.xml
:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:listPreferredItemHeightSmall">20dp</item>
</style>
You may need to modify this number a bit to get the correct value, but it determines the height of those rows. Make sure to replace Theme.AppCompat.Light.DarkActionBar
with whatever you're currently using.
As for setting a maximum height, I'm afraid you'll have to create your own extension class for that, as in this example.
one extra question: when deal with those standard android styles... how can i know which one to override without trying a lots of them? ( i knew there was a styles for that but couldn't figure out which)
– Rafael Lima
Jan 30 at 3:19
1
Unfortunately, the answer is googling it or looking on Stack overflow. The answers can be found in the documentation, but it's usually pretty hard to find yourself.
– JakeSteam
Jan 30 at 7:13
add a comment |
You need to set your preferred item row height in your AppTheme inside styles.xml
:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:listPreferredItemHeightSmall">20dp</item>
</style>
You may need to modify this number a bit to get the correct value, but it determines the height of those rows. Make sure to replace Theme.AppCompat.Light.DarkActionBar
with whatever you're currently using.
As for setting a maximum height, I'm afraid you'll have to create your own extension class for that, as in this example.
You need to set your preferred item row height in your AppTheme inside styles.xml
:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:listPreferredItemHeightSmall">20dp</item>
</style>
You may need to modify this number a bit to get the correct value, but it determines the height of those rows. Make sure to replace Theme.AppCompat.Light.DarkActionBar
with whatever you're currently using.
As for setting a maximum height, I'm afraid you'll have to create your own extension class for that, as in this example.
edited Jan 17 at 9:07
answered Jan 17 at 8:59


JakeSteamJakeSteam
2,52952542
2,52952542
one extra question: when deal with those standard android styles... how can i know which one to override without trying a lots of them? ( i knew there was a styles for that but couldn't figure out which)
– Rafael Lima
Jan 30 at 3:19
1
Unfortunately, the answer is googling it or looking on Stack overflow. The answers can be found in the documentation, but it's usually pretty hard to find yourself.
– JakeSteam
Jan 30 at 7:13
add a comment |
one extra question: when deal with those standard android styles... how can i know which one to override without trying a lots of them? ( i knew there was a styles for that but couldn't figure out which)
– Rafael Lima
Jan 30 at 3:19
1
Unfortunately, the answer is googling it or looking on Stack overflow. The answers can be found in the documentation, but it's usually pretty hard to find yourself.
– JakeSteam
Jan 30 at 7:13
one extra question: when deal with those standard android styles... how can i know which one to override without trying a lots of them? ( i knew there was a styles for that but couldn't figure out which)
– Rafael Lima
Jan 30 at 3:19
one extra question: when deal with those standard android styles... how can i know which one to override without trying a lots of them? ( i knew there was a styles for that but couldn't figure out which)
– Rafael Lima
Jan 30 at 3:19
1
1
Unfortunately, the answer is googling it or looking on Stack overflow. The answers can be found in the documentation, but it's usually pretty hard to find yourself.
– JakeSteam
Jan 30 at 7:13
Unfortunately, the answer is googling it or looking on Stack overflow. The answers can be found in the documentation, but it's usually pretty hard to find yourself.
– JakeSteam
Jan 30 at 7:13
add a comment |
PopupMenu
items are just regular MenuItem
; it's the same attribute, but another parent style:
<style name="customPopupMenuStyle" parent="@android:style/Widget.PopupMenu">
<item name="android:listPreferredItemHeightSmall">32dp</item>
</style>
this only affects the PopupMenu
to which the style had been assigned to.
also there one could set a custom ActionView
(per individual item, not as a template):
MenuItem item = menu.findItem(R.id.itemMenu);
MenuItemCompat.setActionView(item, R.layout.layout_menu);
this isn't a spinner... i added the code to make it clear
– Rafael Lima
Jan 16 at 23:27
@RafaelLima updated my answer accordingly.
– Martin Zeitler
Jan 19 at 10:15
add a comment |
PopupMenu
items are just regular MenuItem
; it's the same attribute, but another parent style:
<style name="customPopupMenuStyle" parent="@android:style/Widget.PopupMenu">
<item name="android:listPreferredItemHeightSmall">32dp</item>
</style>
this only affects the PopupMenu
to which the style had been assigned to.
also there one could set a custom ActionView
(per individual item, not as a template):
MenuItem item = menu.findItem(R.id.itemMenu);
MenuItemCompat.setActionView(item, R.layout.layout_menu);
this isn't a spinner... i added the code to make it clear
– Rafael Lima
Jan 16 at 23:27
@RafaelLima updated my answer accordingly.
– Martin Zeitler
Jan 19 at 10:15
add a comment |
PopupMenu
items are just regular MenuItem
; it's the same attribute, but another parent style:
<style name="customPopupMenuStyle" parent="@android:style/Widget.PopupMenu">
<item name="android:listPreferredItemHeightSmall">32dp</item>
</style>
this only affects the PopupMenu
to which the style had been assigned to.
also there one could set a custom ActionView
(per individual item, not as a template):
MenuItem item = menu.findItem(R.id.itemMenu);
MenuItemCompat.setActionView(item, R.layout.layout_menu);
PopupMenu
items are just regular MenuItem
; it's the same attribute, but another parent style:
<style name="customPopupMenuStyle" parent="@android:style/Widget.PopupMenu">
<item name="android:listPreferredItemHeightSmall">32dp</item>
</style>
this only affects the PopupMenu
to which the style had been assigned to.
also there one could set a custom ActionView
(per individual item, not as a template):
MenuItem item = menu.findItem(R.id.itemMenu);
MenuItemCompat.setActionView(item, R.layout.layout_menu);
edited Jan 19 at 10:18
answered Jan 14 at 23:26


Martin ZeitlerMartin Zeitler
19k34373
19k34373
this isn't a spinner... i added the code to make it clear
– Rafael Lima
Jan 16 at 23:27
@RafaelLima updated my answer accordingly.
– Martin Zeitler
Jan 19 at 10:15
add a comment |
this isn't a spinner... i added the code to make it clear
– Rafael Lima
Jan 16 at 23:27
@RafaelLima updated my answer accordingly.
– Martin Zeitler
Jan 19 at 10:15
this isn't a spinner... i added the code to make it clear
– Rafael Lima
Jan 16 at 23:27
this isn't a spinner... i added the code to make it clear
– Rafael Lima
Jan 16 at 23:27
@RafaelLima updated my answer accordingly.
– Martin Zeitler
Jan 19 at 10:15
@RafaelLima updated my answer accordingly.
– Martin Zeitler
Jan 19 at 10:15
add a comment |
You can create a layout for popup menu and initialize it in your activity as follows
XML
> <?xml version="1.0" encoding="utf-8"?> <LinearLayout
> xmlns:android="http://schemas.android.com/apk/res/android"
> android:layout_width="match_parent"
> android:layout_height="match_parent"
> android:gravity="center"
> android:background="@android:color/transparent">
> <LinearLayout
> android:layout_width="wrap_content"
> android:layout_height="YOUR MAX HEIGHT"
> android:gravity="center"
> android:weightsum="YOUR NUMBER OF ITEMS"
> android:orientation="vertical"
> android:layout_gravity="center"
> >
> <TextView
> android:layout_width="wrap_content"
> android:layout_height="0dp"
> android:weight="1" /> ...no of views items
> </LinearLayout> </LinearLayout>
INITIALIZE IT AS
View parentv = findViewById(R.id.activityview); //id of parent view of activity in which popup will be shown
LayoutInflater layoutInflater
= (LayoutInflater) getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.YOURPOPUPMENU, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.MATCH_PARENT);
TextView tv = popupView.findViewById(R.id.textviewid); //to do something with textview
tv.setText("Fashion");
popupWindow.setOutsideTouchable(true); //if you want to dismiss popup if clicked outside
popupWindow.setFocusable(true);
// Removes default background.
popupWindow.setBackgroundDrawable(new android.graphics.drawable.ColorDrawable(android.graphics.Color.TRANSPARENT));
// popupWindow.setAnimationStyle(R.style.righttoleftstyle); can put animation to slide in popupmenu by defining any animation
popupWindow.showAtLocation(parentv, Gravity.START | Gravity.TOP,0,0);
//will show popup on top left corner of the screen of the activity view you can try some iterations for it to show where on screen according to your needs
I hope it will help!
add a comment |
You can create a layout for popup menu and initialize it in your activity as follows
XML
> <?xml version="1.0" encoding="utf-8"?> <LinearLayout
> xmlns:android="http://schemas.android.com/apk/res/android"
> android:layout_width="match_parent"
> android:layout_height="match_parent"
> android:gravity="center"
> android:background="@android:color/transparent">
> <LinearLayout
> android:layout_width="wrap_content"
> android:layout_height="YOUR MAX HEIGHT"
> android:gravity="center"
> android:weightsum="YOUR NUMBER OF ITEMS"
> android:orientation="vertical"
> android:layout_gravity="center"
> >
> <TextView
> android:layout_width="wrap_content"
> android:layout_height="0dp"
> android:weight="1" /> ...no of views items
> </LinearLayout> </LinearLayout>
INITIALIZE IT AS
View parentv = findViewById(R.id.activityview); //id of parent view of activity in which popup will be shown
LayoutInflater layoutInflater
= (LayoutInflater) getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.YOURPOPUPMENU, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.MATCH_PARENT);
TextView tv = popupView.findViewById(R.id.textviewid); //to do something with textview
tv.setText("Fashion");
popupWindow.setOutsideTouchable(true); //if you want to dismiss popup if clicked outside
popupWindow.setFocusable(true);
// Removes default background.
popupWindow.setBackgroundDrawable(new android.graphics.drawable.ColorDrawable(android.graphics.Color.TRANSPARENT));
// popupWindow.setAnimationStyle(R.style.righttoleftstyle); can put animation to slide in popupmenu by defining any animation
popupWindow.showAtLocation(parentv, Gravity.START | Gravity.TOP,0,0);
//will show popup on top left corner of the screen of the activity view you can try some iterations for it to show where on screen according to your needs
I hope it will help!
add a comment |
You can create a layout for popup menu and initialize it in your activity as follows
XML
> <?xml version="1.0" encoding="utf-8"?> <LinearLayout
> xmlns:android="http://schemas.android.com/apk/res/android"
> android:layout_width="match_parent"
> android:layout_height="match_parent"
> android:gravity="center"
> android:background="@android:color/transparent">
> <LinearLayout
> android:layout_width="wrap_content"
> android:layout_height="YOUR MAX HEIGHT"
> android:gravity="center"
> android:weightsum="YOUR NUMBER OF ITEMS"
> android:orientation="vertical"
> android:layout_gravity="center"
> >
> <TextView
> android:layout_width="wrap_content"
> android:layout_height="0dp"
> android:weight="1" /> ...no of views items
> </LinearLayout> </LinearLayout>
INITIALIZE IT AS
View parentv = findViewById(R.id.activityview); //id of parent view of activity in which popup will be shown
LayoutInflater layoutInflater
= (LayoutInflater) getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.YOURPOPUPMENU, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.MATCH_PARENT);
TextView tv = popupView.findViewById(R.id.textviewid); //to do something with textview
tv.setText("Fashion");
popupWindow.setOutsideTouchable(true); //if you want to dismiss popup if clicked outside
popupWindow.setFocusable(true);
// Removes default background.
popupWindow.setBackgroundDrawable(new android.graphics.drawable.ColorDrawable(android.graphics.Color.TRANSPARENT));
// popupWindow.setAnimationStyle(R.style.righttoleftstyle); can put animation to slide in popupmenu by defining any animation
popupWindow.showAtLocation(parentv, Gravity.START | Gravity.TOP,0,0);
//will show popup on top left corner of the screen of the activity view you can try some iterations for it to show where on screen according to your needs
I hope it will help!
You can create a layout for popup menu and initialize it in your activity as follows
XML
> <?xml version="1.0" encoding="utf-8"?> <LinearLayout
> xmlns:android="http://schemas.android.com/apk/res/android"
> android:layout_width="match_parent"
> android:layout_height="match_parent"
> android:gravity="center"
> android:background="@android:color/transparent">
> <LinearLayout
> android:layout_width="wrap_content"
> android:layout_height="YOUR MAX HEIGHT"
> android:gravity="center"
> android:weightsum="YOUR NUMBER OF ITEMS"
> android:orientation="vertical"
> android:layout_gravity="center"
> >
> <TextView
> android:layout_width="wrap_content"
> android:layout_height="0dp"
> android:weight="1" /> ...no of views items
> </LinearLayout> </LinearLayout>
INITIALIZE IT AS
View parentv = findViewById(R.id.activityview); //id of parent view of activity in which popup will be shown
LayoutInflater layoutInflater
= (LayoutInflater) getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.YOURPOPUPMENU, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.MATCH_PARENT);
TextView tv = popupView.findViewById(R.id.textviewid); //to do something with textview
tv.setText("Fashion");
popupWindow.setOutsideTouchable(true); //if you want to dismiss popup if clicked outside
popupWindow.setFocusable(true);
// Removes default background.
popupWindow.setBackgroundDrawable(new android.graphics.drawable.ColorDrawable(android.graphics.Color.TRANSPARENT));
// popupWindow.setAnimationStyle(R.style.righttoleftstyle); can put animation to slide in popupmenu by defining any animation
popupWindow.showAtLocation(parentv, Gravity.START | Gravity.TOP,0,0);
//will show popup on top left corner of the screen of the activity view you can try some iterations for it to show where on screen according to your needs
I hope it will help!
answered Jan 21 at 16:11
Vanshaj DagaVanshaj Daga
44427
44427
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53999449%2fhow-to-change-margin-between-items-in-popupmenu%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown