I have been trying to do such a pop up menu. However, I am not able to do it since I can not put pictures and give design in pop-up menu. Does any one know to do such a pop menu?
Go to this link. I hope this will help you achieving what you want.
An example for pop up menu is here.
EDIT
Create an PopUpWindow layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/llSortChangePopup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/sort_popup_background"
android:orientation="vertical" >
<TextView
android:id="#+id/tvDistance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/distance"
android:layout_weight="1.0"
android:layout_marginLeft="20dp"
android:paddingTop="5dp"
android:gravity="center_vertical"
android:textColor="#color/my_darker_gray" />
<ImageView
android:layout_marginLeft="11dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/sort_popup_devider"
android:contentDescription="#drawable/sort_popup_devider"/>
<TextView
android:id="#+id/tvPriority"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/priority"
android:layout_weight="1.0"
android:layout_marginLeft="20dp"
android:gravity="center_vertical"
android:clickable="true"
android:onClick="popupSortOnClick"
android:textColor="#color/my_black" />
<ImageView
android:layout_marginLeft="11dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/sort_popup_devider"
android:contentDescription="#drawable/sort_popup_devider"/>
<TextView
android:id="#+id/tvTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/time"
android:layout_weight="1.0"
android:layout_marginLeft="20dp"
android:gravity="center_vertical"
android:clickable="true"
android:onClick="popupSortOnClick"
android:textColor="#color/my_black" />
<ImageView
android:layout_marginLeft="11dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/sort_popup_devider"
android:contentDescription="#drawable/sort_popup_devider"/>
<TextView
android:id="#+id/tvStatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/status"
android:layout_weight="1.0"
android:layout_marginLeft="20dp"
android:gravity="center_vertical"
android:textColor="#color/my_black"
android:clickable="true"
android:onClick="popupSortOnClick"
android:paddingBottom="10dp"/>
</LinearLayout>
and then create the PopUpWindow in your Activity:
// The method that displays the popup.
private void showStatusPopup(final Activity context, Point p) {
// Inflate the popup_layout.xml
LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.llStatusChangePopup);
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.status_popup_layout, null);
// Creating the PopupWindow
changeStatusPopUp = new PopupWindow(context);
changeStatusPopUp.setContentView(layout);
changeStatusPopUp.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
changeStatusPopUp.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
changeStatusPopUp.setFocusable(true);
// Some offset to align the popup a bit to the left, and a bit down, relative to button's position.
int OFFSET_X = -20;
int OFFSET_Y = 50;
//Clear the default translucent background
changeStatusPopUp.setBackgroundDrawable(new BitmapDrawable());
// Displaying the popup at the specified location, + offsets.
changeStatusPopUp.showAtLocation(layout, Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y + OFFSET_Y);
}
finally pop it it up onClick of a button or anything else:
imTaskStatusButton.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
int[] location = new int[2];
currentRowId = position;
currentRow = v;
// Get the x, y location and store it in the location[] array
// location[0] = x, location[1] = y.
v.getLocationOnScreen(location);
//Initialize the Point with x, and y positions
point = new Point();
point.x = location[0];
point.y = location[1];
showStatusPopup(TasksListActivity.this, point);
}
});
Related
I want to achieve exactly like PopupMenu with icons On layout click which is in Custom Toolbar . So , i have taken the help of an answer but issue i am facing is : Nothing is poping out on click .
POPLayout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/poplayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="200dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/home" />
<TextView
android:id="#+id/tvDistance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HOME"
android:layout_marginLeft="20dp"
android:paddingTop="5dp"
android:gravity="center_vertical"
android:textColor="#color/backgroud_user" />
</LinearLayout>
<LinearLayout
android:layout_width="200dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/ic_cloud_upload" />
<TextView
android:id="#+id/cloud"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CHECKIN"
android:layout_marginLeft="20dp"
android:paddingTop="5dp"
android:gravity="center_vertical"
android:textColor="#color/backgroud_user" />
</LinearLayout>
</LinearLayout>
Toolbar.xml(consist of an layout to be clicked)
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="#dimen/toolbar_height"
android:background="#color/toolbar_color"
android:contentInsetLeft="0dp"
android:contentInsetStart="0dp"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textview"
android:text="My Assignments"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginLeft="90dp"
android:layout_weight="0.5"
android:textSize="20sp"
/>
<LinearLayout(**layout to be clicked**)
android:layout_width="35dp"
android:layout_height="35dp"
android:background="#75aadb"
android:id="#+id/accountinfo_layout"
android:layout_gravity="center"
android:layout_marginLeft="10dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:src="#drawable/account"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>
Code.class
accountInfoLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(point!=null){
int[] location = new int[2];
v.getLocationOnScreen(location);
point = new Point();
point.x = location[0];
point.y = location[1];
showPopup(getActivity(),point);
}
// The method that displays the popup.
private void showPopup(final Activity context, Point p) {
int popupWidth = 200;
int popupHeight = 150;
// Inflate the popup_layout.xml
LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.poplayout);
LayoutInflater layoutInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.pop_window, viewGroup);
// Creating the PopupWindow
final PopupWindow popup = new PopupWindow(context);
popup.setContentView(layout);
popup.setWidth(popupWidth);
popup.setHeight(popupHeight);
popup.setFocusable(true);
// Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
int OFFSET_X = 30;
int OFFSET_Y = 30;
// Clear the default translucent background
popup.setBackgroundDrawable(new BitmapDrawable());
// Displaying the popup at the specified location, + offsets.
popup.showAtLocation(layout, Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y + OFFSET_Y);
}
Nothing in showing on click . Please help me in finding Bug .
I think just remove if(point!=null) condition it will work
accountInfoLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int[] location = new int[2];
v.getLocationOnScreen(location);
point = new Point();
point.x = location[0];
point.y = location[1];
showPopup(getActivity(),point);
}
}
}
I have founded many solutions for this problem but none of them have worked for me. I want to show a PopupWindow inside a Fragment. This is my code
LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
View popupView = layoutInflater.inflate(R.layout.pop_up_cargando, null,false);
this.popupWindow = new PopupWindow(popupView, popupView.getWidth(),popupView.getHeight());
this.popupWindow.setFocusable(true);
int location[] = new int[2];
this.btnInventario.getLocationOnScreen(location);
this.popupWindow.showAtLocation(this.btnInventario, Gravity.NO_GRAVITY, location[0], location[1] + btnInventario.getHeight()); // this.btnInventario is the button that calls this code
this.popupWindow.update(0, 0, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
But the PopupWindow never appears.
Edit: This is the content of pop_up_cargando
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/popup_recomendar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="vertical" >
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="20dp"
android:layout_gravity="center"
android:id="#+id/cargando"/>
<TextView
android:id="#+id/txtTexto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_gravity="center"
android:text="#string/vacio"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
Any suggestions? What I'm doing wrong? Your help will be very appreciated.
Your popupView.getWidth() and popupView.getHeight() values are equals to 0 because the view has not been drawn yet.
Before asking for the width and the height of your view, you have to ensure that it has been drawn. For that you can call the following method after it has been inflated:
popupView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
After that, the size of your view is available with the methods getMeasuredWidth() and getMeasuredHeight().
How Do i make this view. I checked Spinner and PopUp window but i failed to do... Please suggest me any examples...
you should go for Android QuickAction widget.
This is an open source project of GithUb.
https://github.com/lorensiuswlt/NewQuickAction3D
https://github.com/alhneiti/Android-QuickAction
Hope this will help you.
I have achived this kind of behavior using a PopUpWindow, here is my code:
// The method that displays the popup.
private void showStatusPopup(final Activity context, Point p) {
// Inflate the popup_layout.xml
LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.llStatusChangePopup);
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.status_popup_layout, null);
// Creating the PopupWindow
changeStatusPopUp = new PopupWindow(context);
changeStatusPopUp.setContentView(layout);
changeStatusPopUp.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
changeStatusPopUp.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
changeStatusPopUp.setFocusable(true);
// Some offset to align the popup a bit to the left, and a bit down, relative to button's position.
int OFFSET_X = -20;
int OFFSET_Y = 50;
//Clear the default translucent background
changeStatusPopUp.setBackgroundDrawable(new BitmapDrawable());
// Displaying the popup at the specified location, + offsets.
changeStatusPopUp.showAtLocation(layout, Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y + OFFSET_Y);
}
and this is the PopUp layout:
<?xml version="1.0" encoding="utf-8"?>
<ImageView
android:layout_marginLeft="11dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/devider_popup_task_status_change"
android:contentDescription="#drawable/devider_popup_task_status_change"/>
<TextView
android:id="#+id/tvInProgress"
android:paddingLeft="10dp"
android:layout_weight="1.0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/my_black"
android:gravity="center_vertical"
android:clickable="true"
android:onClick="popupStatusChangeOnClick"
android:layout_marginLeft="11dp"
android:layout_marginRight="4dp"
android:text="#string/inprogress"/>
<ImageView
android:layout_marginLeft="11dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/devider_popup_task_status_change"
android:contentDescription="#drawable/devider_popup_task_status_change"/>
<TextView
android:id="#+id/tvOnTheWay"
android:paddingLeft="10dp"
android:layout_weight="1.0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/my_black"
android:gravity="center_vertical"
android:clickable="true"
android:onClick="popupStatusChangeOnClick"
android:layout_marginLeft="11dp"
android:layout_marginRight="4dp"
android:text="#string/ontheway"/>
<ImageView
android:layout_marginLeft="11dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/devider_popup_task_status_change"
android:contentDescription="#drawable/devider_popup_task_status_change"/>
<TextView
android:id="#+id/tvComplete"
android:paddingLeft="10dp"
android:layout_weight="1.0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/my_black"
android:gravity="center_vertical"
android:clickable="true"
android:onClick="popupStatusChangeOnClick"
android:layout_marginLeft="11dp"
android:layout_marginRight="4dp"
android:text="#string/complete"/>
<ImageView
android:layout_marginLeft="11dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/devider_popup_task_status_change"
android:contentDescription="#drawable/devider_popup_task_status_change"/>
<TextView
android:id="#+id/tvFailed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:layout_weight="1.0"
android:gravity="center_vertical"
android:clickable="true"
android:onClick="popupStatusChangeOnClick"
android:layout_marginLeft="11dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="11dp"
android:text="#string/failed"
android:textColor="#color/my_black" />
When the ImageView's are only a 1 pixel deviders.
What you ask about is a Spinner, but you can also make your own popup list, using "ListPopupWindow"
you can use spinner also-
String[] branch={"NEW","prev",...};
ArrayAdapter<String> list;
spinner=(Spinner) findViewById(R.id.spinner);
list=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,branch);
spinner.setAdapter(list);
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
}
Can someone help me. I have a popup window and how can i autoscale it for every resolution of android devices it must be in the center of my application?
This is my main.java
public void onWindowFocusChanged(boolean hasFocus) {
int[] location = new int[2];
Button button = (Button) findViewById(R.id.show_popup);
// Get the x, y location and store it in the location[] array
// location[0] = x, location[1] = y.
button.getLocationOnScreen(location);
//Initialize the Point with x, and y positions
p = new Point();
p.x = location[0];
p.y = location[1];
}
// The method that displays the popup.
private void showPopup(final Activity context, Point p) {
int popupWidth = 230;
int popupHeight = 300;
// Inflate the popup_layout.xml
LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.popup);
LayoutInflater layoutInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.popup_layout, viewGroup);
// Creating the PopupWindow
final PopupWindow popup = new PopupWindow(context);
popup.setContentView(layout);
popup.setWidth(popupWidth);
popup.setHeight(popupHeight);
popup.setFocusable(true);
// Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
// Clear the default translucent background
// Displaying the popup at the specified location, + offsets.
popup.showAtLocation(layout, Gravity.CENTER, 0,0);
// Getting a reference to Close button, and close the popup when clicked.
Button close = (Button) layout.findViewById(R.id.filter);
close.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
popup.getContentView();
}
});
}
This is my popup_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/popup_bg"
android:orientation="vertical" >
<Button
android:id="#+id/filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/CheckBox04"
android:layout_marginTop="103dp"
android:text="Filter" />
<CheckBox
android:id="#+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="40dp"
/>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Test"
android:textAppearance="?android:attr/textAppearanceLarge" />
<CheckBox
android:id="#+id/CheckBox03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/CheckBox01"
/>
</RelativeLayout>
If you do android:gravity="center" for the layout of your pop-out window, it should center for all devices
I have a problem when creating a popup for my app. I'm trying to show a popup that fills the total size of my screen. The problem is that i'm getting 1px line at the left side that isn't filled.
my popup xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="#+id/popup"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginBottom="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#drawable/popup_round_corners"
android:orientation="vertical"
android:padding="5dp" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:text="#string/zm_main_uvod" />
<Button
android:id="#+id/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginTop="10dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:text="Ok" />
</LinearLayout>
</LinearLAyout>
and my function to show popup:
private void showPopup(final Activity context) {
// Inflate the popup_layout.xml
LinearLayout viewGroup = (LinearLayout)findViewById(R.id.popup);
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.startpopup, viewGroup);
// Creating the PopupWindow
final PopupWindow popup = new PopupWindow(context);
popup.setContentView(layout);
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height=display.getHeight();
popup.setWidth(width+5);
popup.setHeight(height+5);
popup.setFocusable(true);
popup.showAtLocation(layout, Gravity.FILL, 0, 0);
Button close = (Button) layout.findViewById(R.id.close);
close.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
popup.dismiss();
}
});
}
I tried with gravity.center and try setting offsets to -30,-30 but nothing happend. Any ideas?