本文整理汇总了Java中android.widget.PopupWindow.showAtLocation方法的典型用法代码示例。如果您正苦于以下问题:Java PopupWindow.showAtLocation方法的具体用法?Java PopupWindow.showAtLocation怎么用?Java PopupWindow.showAtLocation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.PopupWindow
的用法示例。
在下文中一共展示了PopupWindow.showAtLocation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: progressPopUp
import android.widget.PopupWindow; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public void progressPopUp(final Activity context,String data){
RelativeLayout layoutId = (RelativeLayout)context.findViewById(R.id.dialog_rootView);
LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.progresspopup, layoutId);
txtWaiting = (TextView)layout.findViewById(R.id.txtWaiting);
paymentAlert = new PopupWindow(context);
paymentAlert.setContentView(layout);
paymentAlert.setHeight(WindowManager.LayoutParams.MATCH_PARENT);
paymentAlert.setWidth(WindowManager.LayoutParams.MATCH_PARENT);
paymentAlert.setFocusable(true);
paymentAlert.setBackgroundDrawable(new BitmapDrawable());
paymentAlert.showAtLocation(layout, Gravity.CENTER, 0, 0);
if(data !=null)
txtWaiting.setText(data);
}
示例2: showPopUpWindow
import android.widget.PopupWindow; //导入方法依赖的package包/类
private void showPopUpWindow(View view) {
WindowManager systemService = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
int width = systemService.getDefaultDisplay().getWidth();
int height = systemService.getDefaultDisplay().getHeight();
int popWidth = (int) (width * 0.75);
int popHeight = (int) (height * 0.64);
PopupWindow popupWindow = new PopupWindow(this);
popupWindow.setWidth(popWidth);
popupWindow.setHeight(popHeight);
View inflate = LayoutInflater.from(this).inflate(R.layout.ll_life_detail_pop,null);
popupWindow.setContentView(inflate);
popupWindow.setClippingEnabled(false);//设置覆盖状态栏,重点
popupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.rl_pop_top_corner));
popupWindow.setOutsideTouchable(false);
popupWindow.setFocusable(true);
popupWindow.showAtLocation(view, Gravity.CENTER,0,0);
initPopUpView(inflate);
}
示例3: showActionMenu
import android.widget.PopupWindow; //导入方法依赖的package包/类
/**
* 长按弹出菜单
*
* @param offsetY
* @param actionMenu
* @return 菜单创建成功,返回true
*/
private void showActionMenu(int offsetY, ActionMenu actionMenu) {
mActionMenuPopupWindow = new PopupWindow(actionMenu, WindowManager.LayoutParams.WRAP_CONTENT,
mActionMenuHeight, true);
mActionMenuPopupWindow.setFocusable(true);
mActionMenuPopupWindow.setOutsideTouchable(false);
mActionMenuPopupWindow.setBackgroundDrawable(new ColorDrawable(0x00000000));
mActionMenuPopupWindow.showAtLocation(this, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, offsetY);
mActionMenuPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
Selection.removeSelection(getEditableText());
// 如果设置了分散对齐,ActionMenu销毁后,强制刷新一次,防止出现文字背景未消失的情况
if (isTextJustify)
SelectableTextView.this.postInvalidate();
}
});
}
示例4: resultWindow
import android.widget.PopupWindow; //导入方法依赖的package包/类
private PopupWindow resultWindow(View view){
//View view = LayoutInflater.from(getActivity()).inflate(R.layout.classify_result, null);
//1.构造一个PopupWindow,参数依次是加载的View,宽高
final PopupWindow popWindow = new PopupWindow(view,
400, ViewGroup.LayoutParams.WRAP_CONTENT);
//final PopupWindow popWindow = new PopupWindow(this.getActivity());
//popWindow.setAnimationStyle(R.anim.anim_pop); //设置加载动画
//这些为了点击非PopupWindow区域,PopupWindow会消失的,如果没有下面的
//代码的话,你会发现,当你把PopupWindow显示出来了,无论你按多少次后退键
//PopupWindow并不会关闭,而且退不出程序,加上下述代码可以解决这个问题
popWindow.setOutsideTouchable(true);
popWindow.setTouchable(true);
popWindow.setTouchInterceptor(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return false;
// 这里如果返回true的话,touch事件将被拦截
// 拦截后 PopupWindow的onTouchEvent不被调用,这样点击外部区域无法dismiss
}
});
popWindow.setBackgroundDrawable(new ColorDrawable(0x11111111)); //要为popWindow设置一个背景才有效
//设置popupWindow显示的位置
popWindow.showAtLocation(view, Gravity.CENTER, 0, 0);
return popWindow;
}
示例5: onClick
import android.widget.PopupWindow; //导入方法依赖的package包/类
@Override
public void onClick(final View widget) {
View view = LayoutInflater.from(context).inflate(R.layout.layout_input, null);
final EditText etInput = (EditText) view.findViewById(R.id.et_answer);
Button btnFillBlank = (Button) view.findViewById(R.id.btn_fill_blank);
// 显示原有答案
String oldAnswer = answerList.get(position);
if (!TextUtils.isEmpty(oldAnswer)) {
etInput.setText(oldAnswer);
etInput.setSelection(oldAnswer.length());
}
final PopupWindow popupWindow = new PopupWindow(view, LayoutParams.MATCH_PARENT, dp2px(40));
// 获取焦点
popupWindow.setFocusable(true);
// 为了防止弹出菜单获取焦点之后,点击Activity的其他组件没有响应
popupWindow.setBackgroundDrawable(new PaintDrawable());
// 设置PopupWindow在软键盘的上方
popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
// 弹出PopupWindow
popupWindow.showAtLocation(tvContent, Gravity.BOTTOM, 0, 0);
btnFillBlank.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// 填写答案
String answer = etInput.getText().toString();
fillAnswer(answer, position);
popupWindow.dismiss();
}
});
// 显示软键盘
InputMethodManager inputMethodManager =
(InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}
示例6: showShareLayout
import android.widget.PopupWindow; //导入方法依赖的package包/类
private void showShareLayout() {
mSharePopWindow = new PopupWindow(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
View view = LayoutInflater.from(this).inflate(R.layout.sharelayout, null);
view.findViewById(R.id.btn_share_to_circle).setOnClickListener(this);
view.findViewById(R.id.btn_share_to_friend).setOnClickListener(this);
mSharePopWindow.setContentView(view);
mSharePopWindow.setFocusable(false);
mSharePopWindow.setBackgroundDrawable(new BitmapDrawable());
mSharePopWindow.setOutsideTouchable(true);
mSharePopWindow.showAtLocation(findViewById(android.R.id.content), Gravity.BOTTOM,0,0);
}
示例7: dialog
import android.widget.PopupWindow; //导入方法依赖的package包/类
public static PopupWindow dialog(View dialogView, int gravity, int anim, int x, int y, int width, int heigh) {
if (dialogView == null) {
throw new NullPointerException("dialogView is null from method:dialog Class:DialogUtils");
}
PopupWindow popup = new PopupWindow(dialogView, width, heigh);
if (anim != 0) {
popup.setAnimationStyle(anim);
}
popup.setBackgroundDrawable(new BitmapDrawable());
popup.setOutsideTouchable(true);
popup.showAtLocation(dialogView, gravity, x, y);
return popup;
}
示例8: showPop
import android.widget.PopupWindow; //导入方法依赖的package包/类
private void showPop() {
final PopupWindow popupWindow = new PopupWindow(this,null,R.style.bottomDialog);
View view = LayoutInflater.from(this).inflate(R.layout.popup, null);
popupWindow.setContentView(view);
popupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setOutsideTouchable(true);
popupWindow.setTouchable(true);
// popupWindow.setAnimationStyle(R.style.);
popupWindow.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#88000000")));
// popupWindow.showAsDropDown(mButton7, 0, -mButton7.getHeight());//在view下方
//如果是0,0的话,默认是在这个view(anchor锚)的左下角作为起始点
//Gravity.RIGHT代表在view的右下角开始 这个是api19开始支持
//这种显示方式如果是和view无关,里面只是为了获得token
popupWindow.showAtLocation(mButton7, Gravity.BOTTOM|Gravity.LEFT,100,200);
//这个x y的位置是先计算重力所在的位置,然后再以那个位置为左上角,x,y是相对位置
//如果是Gravity.BOTTOM 设置y值不能为负值
//设置了重力后坐标系的方向就变了,如果是Gravity.BOTTOM 那么y轴的方向就是向上
}
示例9: startShowDialog
import android.widget.PopupWindow; //导入方法依赖的package包/类
private void startShowDialog() {
View popMenuView = activity.getLayoutInflater().inflate(R.layout.dialog, null);
RealTimeBlurView blur_view = (RealTimeBlurView) popMenuView.findViewById(R.id.blur_view);
float v = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 15, activity.getResources().getDisplayMetrics());
blur_view.setBlurRadius(v);
final PopupWindow popMenu = new PopupWindow(popMenuView, RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT, true);
popMenu.setClippingEnabled(false);
popMenu.setFocusable(true); //点击其他地方关闭
popMenu.setAnimationStyle(R.style.main_menu_animstyle);
popMenu.showAtLocation(popMenuView, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
}
示例10: buildPopupWindow
import android.widget.PopupWindow; //导入方法依赖的package包/类
private PopupWindow buildPopupWindow(Activity parent) {
LayoutInflater inflater = (LayoutInflater) parent.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewGroup popupViewGroup = parent.findViewById(R.id.popup_layout);
View popupView = inflater.inflate(R.layout.progress_popup_window, popupViewGroup);
PopupWindow popupWindow = new PopupWindow(popupView, 750, 350, true);
popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
popupWindow.setElevation(10);
popupWindow.setFocusable(false);
popupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 0);
return popupWindow;
}
示例11: showAsDropDown
import android.widget.PopupWindow; //导入方法依赖的package包/类
/**
* 展示popupWindow--解决Android 7.0版本兼容性问题
*
* @param mWindow PopupWindow
* @param anchor the view on which to pin the popup window
* @param x A horizontal offset from the anchor in pixels
* @param y A vertical offset from the anchor in pixels
*/
public static void showAsDropDown(PopupWindow mWindow, View anchor, int x, int y) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.N) {
int[] location = new int[2];
anchor.getLocationOnScreen(location);
mWindow.showAtLocation(anchor, Gravity.NO_GRAVITY, location[0] + x, location[1] + anchor.getHeight() + y);
} else {
mWindow.showAsDropDown(anchor, x, y);
}
}
示例12: showPopupWindow
import android.widget.PopupWindow; //导入方法依赖的package包/类
/**
* 把一个View控件添加到PopupWindow上并且显示
*
* @param activity
*/
public void showPopupWindow(Activity activity) {
popupWindow = new PopupWindow(mMenuView, // 添加到popupWindow
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
// ☆ 注意: 必须要设置背景,播放动画有一个前提 就是窗体必须有背景
popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
popupWindow.showAtLocation(activity.getWindow().getDecorView(), Gravity.CENTER | Gravity.BOTTOM, 0, 0);
popupWindow.setAnimationStyle(android.R.style.Animation_InputMethod); // 设置窗口显示的动画效果
popupWindow.setFocusable(false); // 点击其他地方隐藏键盘 popupWindow
popupWindow.update();
}
示例13: resultWindow_1
import android.widget.PopupWindow; //导入方法依赖的package包/类
private PopupWindow resultWindow_1(View view,String text){
//View view = LayoutInflater.from(getActivity()).inflate(R.layout.classify_result, null);
//1.构造一个PopupWindow,参数依次是加载的View,宽高
final PopupWindow popWindow = new PopupWindow(view,
400, ViewGroup.LayoutParams.WRAP_CONTENT);
TextView result=(TextView)view.findViewById(R.id.classify_result_text);
result.setText(text);
//final PopupWindow popWindow = new PopupWindow(this.getActivity());
//popWindow.setAnimationStyle(R.anim.anim_pop); //设置加载动画
//这些为了点击非PopupWindow区域,PopupWindow会消失的,如果没有下面的
//代码的话,你会发现,当你把PopupWindow显示出来了,无论你按多少次后退键
//PopupWindow并不会关闭,而且退不出程序,加上下述代码可以解决这个问题
popWindow.setOutsideTouchable(true);
popWindow.setTouchable(true);
popWindow.setTouchInterceptor(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return false;
// 这里如果返回true的话,touch事件将被拦截
// 拦截后 PopupWindow的onTouchEvent不被调用,这样点击外部区域无法dismiss
}
});
popWindow.setBackgroundDrawable(new ColorDrawable(0x11111111)); //要为popWindow设置一个背景才有效
//设置popupWindow显示的位置
popWindow.showAtLocation(view, Gravity.CENTER, 0, 0);
return popWindow;
}
示例14: showBottomPopupMenu
import android.widget.PopupWindow; //导入方法依赖的package包/类
/**
* 显示底部菜单栏
*
* @param popupWindow
*/
public void showBottomPopupMenu(final PopupWindow popupWindow, final int background)
{
popupWindow.showAtLocation(rocky_rootView, Gravity.BOTTOM, 0, 0);
getUiHandler().postDelayed(new Runnable()
{
@Override
public void run()
{
setBottomPopupMenuBackground(background);
setBottomPopupMenuVisibility(View.VISIBLE);
}
}, 500);
}
示例15: show
import android.widget.PopupWindow; //导入方法依赖的package包/类
public void show(){
/** Object */
LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = inflater.inflate(R.layout.element_popup, null);
CardView pop_up_card = (CardView) popupView.findViewById(R.id.pop_up_card);
element_lay = (RelativeLayout) popupView.findViewById(R.id.element);
/** Text */
TextView symbol = (TextView) popupView.findViewById(R.id.pop_symbol);
TextView number = (TextView) popupView.findViewById(R.id.pop_number);
TextView mass = (TextView) popupView.findViewById(R.id.pop_mass);
TextView native_name = (TextView) popupView.findViewById(R.id.pop_native_name);
TextView second_name = (TextView) popupView.findViewById(R.id.pop_second_name);
symbol.setText(element.getElementSymbol());
number.setText(String.valueOf(element.getElementNumber()));
mass.setText(String.valueOf(element.getAtomicWeight()));
native_name.setText(element.getElementNativeName());
this.colorise(element.getBlockName());
if(element.isRadioactive()) {//show logo of radioactive
}
boolean focusable = true;
int width = LinearLayout.LayoutParams.WRAP_CONTENT;
int height = LinearLayout.LayoutParams.WRAP_CONTENT;
int[] location = new int[2];
element.getLocationOnScreen(location);
int x = location[0];
int y = location[1];
Log.d("Coords", "X: " + String.valueOf(x) + " Y: " + String.valueOf(y));
popupWindow = new PopupWindow(popupView, width, height, focusable);
popupWindow.setAnimationStyle(R.style.PopupWindowAnimation);
popupWindow.showAtLocation(parentView, Gravity.NO_GRAVITY, x, y - element.getHeight() * 3);
popupView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
popupWindow.dismiss();
return true;
}
});
}