Java Code Examples for android.widget.PopupWindow#showAsDropDown()
The following examples show how to use
android.widget.PopupWindow#showAsDropDown() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HomePageSearchFragment.java From tysq-android with GNU General Public License v3.0 | 6 votes |
private void showPopupWindow() { View window = getLayoutInflater() .inflate(R.layout.fragment_home_page_search_popupwindow, null); window.findViewById(R.id.tv_article).setOnClickListener(this); window.findViewById(R.id.tv_label).setOnClickListener(this); window.findViewById(R.id.tv_admin).setOnClickListener(this); mTypeWindow = new PopupWindow(window, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true); mTypeWindow.setOutsideTouchable(true); mTypeWindow.showAsDropDown(tvType, -tvType.getWidth() / 2, tvType.getHeight() / 2); }
Example 2
Source File: MainActivity.java From cwac-security with Apache License 2.0 | 6 votes |
protected void showPopupWindow() { Button popupContent=new Button(this); popupContent.setText(R.string.label_click); popupContent.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); popupContent.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); final PopupWindow popup= new PopupWindow(popupContent, popupContent.getMeasuredWidth(), popupContent.getMeasuredHeight(), true); popupContent.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { popup.dismiss(); } }); popup.showAsDropDown(popupAnchor); }
Example 3
Source File: PopupWindowUtils.java From LQRWeChat with MIT License | 6 votes |
/** * 得到一个自动识别在目标控件上方或下方的pupupwindow并显示 * * @param contentView popupwindow要显示的视图 * @param width popupwindow的宽度 * @param activity 能得到getWindowManager()的上下文 * @return */ public static PopupWindow getPopupWindowAsDropDownParentAuto(View contentView, int width, int height, View anchorView, Activity activity) { // View itemView = (View) contentView.getParent();// 得到contentView的父控件 PopupWindow popupWindow = getPopupWindow(contentView, width, height); // 控制它放置的位置 if (isShowBottom(activity, anchorView)) {// 显示popupwindow在itemView的下方,偏移量都为0 popupWindow.showAsDropDown(anchorView, 0, 0); } else {// 显示popupwindow在itemView的上方,偏移量y都为-2*itemView.getHeight() popupWindow.showAsDropDown(anchorView, 0, -2 * anchorView.getHeight()); } return popupWindow; }
Example 4
Source File: MainActivity.java From DoubleHeadedDragonBar with MIT License | 6 votes |
public void popup(View view){ // 用于PopupWindow的View View contentView=LayoutInflater.from(this).inflate(R.layout.pp_layout, null, false); PopupWindow window=new PopupWindow(contentView, 500, 500, true); window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); window.setOutsideTouchable(true); window.setTouchable(true); final DoubleHeadedDragonBar bar3 = contentView.findViewById(R.id.bar3); bar3.setUnit("0", "100"); bar3.setMinValue(10); bar3.setMaxValue(80); TextView testView2 = (TextView) LayoutInflater.from(this).inflate(R.layout.toast_view, null); bar3.setToastView(testView2); TextView testView1 = (TextView) LayoutInflater.from(this).inflate(R.layout.toast_view, null); bar3.setToastView1(testView1); window.showAsDropDown(view); window.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { bar3.close(); } }); }
Example 5
Source File: MainActivity.java From Study_Android_Demo with Apache License 2.0 | 6 votes |
public void doClick(View view) { //AlertDialog���� // 1.����AlertDialog // AlertDialog dialog = new AlertDialog.Builder(this).setTitle("title") // .setMessage("message").create(); // 2.ͨ��Dialog��ȡWindow // Window window = dialog.getWindow(); // window.setGravity(Gravity.BOTTOM); // �˴���������dialog��ʾ��λ�� // 3.��Window�������ö������ // window.setWindowAnimations(R.style.dialogWindowAnim); // ��Ӷ��� // ��ʾ�Ի��� // dialog.show(); //popupwindow�Ķ��� View popupwindow = getLayoutInflater().inflate( R.layout.popupwindow_layout, null); PopupWindow pop = new PopupWindow(popupwindow, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); pop.setAnimationStyle(R.style.dialogWindowAnim); pop.showAsDropDown(view); }
Example 6
Source File: AnimHelper.java From mvvm-template with GNU General Public License v3.0 | 6 votes |
@UiThread public static void revealPopupWindow(@NonNull PopupWindow popupWindow, @NonNull View from) { Rect rect = ViewHelper.getLayoutPosition(from); int x = (int) rect.exactCenterX(); int y = (int) rect.exactCenterY(); if (popupWindow.getContentView() != null) { View view = popupWindow.getContentView(); if (view != null) { popupWindow.showAsDropDown(from); view.post(() -> { if (ViewCompat.isAttachedToWindow(view)) { Animator animator = ViewAnimationUtils.createCircularReveal(view, x, y, 0, (float) Math.hypot(rect.width(), rect.height())); animator.setDuration(view.getResources().getInteger(android.R.integer.config_shortAnimTime)); animator.start(); } }); } } }
Example 7
Source File: PopupShowAsDropDownActivity.java From AndroidSamples with Apache License 2.0 | 5 votes |
private void showPopupWindow() { View contentView = LayoutInflater.from(PopupShowAsDropDownActivity.this).inflate(R.layout.show_as_drop_down_activity_popup, null); mPopWindow = new PopupWindow(contentView); mPopWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); mPopWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); TextView tv1 = contentView.findViewById(R.id.pop_computer); TextView tv2 = contentView.findViewById(R.id.pop_financial); TextView tv3 = contentView.findViewById(R.id.pop_manage); tv1.setOnClickListener(this); tv2.setOnClickListener(this); tv3.setOnClickListener(this); mPopWindow.showAsDropDown(mMenuTv); }
Example 8
Source File: PopupWindowUtil.java From FastLib with Apache License 2.0 | 5 votes |
/** * 展示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); } }
Example 9
Source File: PostRowViewBinder.java From android-discourse with Apache License 2.0 | 5 votes |
public static void showPopup(View v) { final Context c = v.getContext(); LayoutInflater inflater = LayoutInflater.from(c); TextView contentView = (TextView) inflater.inflate(R.layout.participant_popup_item, null); contentView.setText(v.getContentDescription()); PopupWindow popup = new PopupWindow(c); popup.setContentView(contentView); popup.setOutsideTouchable(true); popup.setWindowLayoutMode(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); popup.setBackgroundDrawable(c.getResources().getDrawable(R.drawable.poster_popup_bg)); popup.showAsDropDown(v, 0, -v.getHeight() * 2); }
Example 10
Source File: TradingFeature.java From settlers-remake with MIT License | 5 votes |
private void materialSelected(View sender, TradeMaterialState materialState) { View popupView = activity.getLayoutInflater().inflate(R.layout.popup_trade_material, null); ImageView infiniteButton = popupView.findViewById(R.id.imageView_tradeButton_infinite); ImageView noneButton = popupView.findViewById(R.id.imageView_tradeButton_none); ImageView eightMoreButton = popupView.findViewById(R.id.imageView_tradeButton_eightMore); ImageView oneMoreButton = popupView.findViewById(R.id.imageView_tradeButton_oneMore); ImageView oneLessButton = popupView.findViewById(R.id.imageView_tradeButton_oneLess); ImageView eightLessButton = popupView.findViewById(R.id.imageView_tradeButton_eightLess); OriginalImageProvider.get(imageInfinite).setAsImage(infiniteButton); OriginalImageProvider.get(imageNone).setAsImage(noneButton); OriginalImageProvider.get(imageEightMore).setAsImage(eightMoreButton); OriginalImageProvider.get(imageOneMore).setAsImage(oneMoreButton); OriginalImageProvider.get(imageOneLess).setAsImage(oneLessButton); OriginalImageProvider.get(imageEightLess).setAsImage(eightLessButton); infiniteButton.setOnClickListener(v -> changeTradeMaterialAmount(materialState.getMaterialType(), Integer.MAX_VALUE, false)); noneButton.setOnClickListener(v -> changeTradeMaterialAmount(materialState.getMaterialType(), 0, false)); eightMoreButton.setOnClickListener(v -> changeTradeMaterialAmount(materialState.getMaterialType(), TRADING_MULTIPLE_STEP_INCREASE, true)); oneMoreButton.setOnClickListener(v -> changeTradeMaterialAmount(materialState.getMaterialType(), 1, true)); oneLessButton.setOnClickListener(v -> changeTradeMaterialAmount(materialState.getMaterialType(), -1, true)); eightLessButton.setOnClickListener(v -> changeTradeMaterialAmount(materialState.getMaterialType(), -TRADING_MULTIPLE_STEP_INCREASE, true)); popupView.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); int xOffset = -((popupView.getMeasuredWidth() - sender.getWidth()) / 2); int yOffset = -(popupView.getMeasuredHeight() + sender.getHeight()); popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, false); popupWindow.setOutsideTouchable(true); popupWindow.showAsDropDown(sender, xOffset, yOffset); }
Example 11
Source File: SandBoxActivity.java From ToDay with MIT License | 5 votes |
private void displayStatsPopup(View anchor) { LayoutInflater layoutInflater = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = layoutInflater.inflate(R.layout.popup_window_flow_stats, null); RelativeLayout viewGroup = (RelativeLayout) layout.findViewById(R.id.popup_stats); // Creating the PopupWindow final PopupWindow popup = new PopupWindow(layout, RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); TextView elementCount = (TextView) viewGroup.findViewById(R.id.stats_total_elements); TextView timeEstimate = (TextView) viewGroup.findViewById(R.id.stats_total_time); TextView completeCount = (TextView) viewGroup.findViewById(R.id.stats_times_complete); TextView lifeTimeInFlow = (TextView) viewGroup.findViewById(R.id.stats_life_time_spent_in_flow); elementCount.setText( String.valueOf(currentToDay.getChildCount()) ); timeEstimate.setText( String.valueOf(currentToDay.getFormattedTime()) ); completeCount.setText( String.valueOf(currentToDay.getCompletionTokens()) ); lifeTimeInFlow.setText( String.valueOf( AppUtils.buildTimerStyleTime(currentToDay.getLifeTimeInToDay())) ); popup.setBackgroundDrawable(new BitmapDrawable(null,"")); popup.setFocusable(true); popup.showAsDropDown(anchor); }
Example 12
Source File: TestActivity.java From YCDialog with Apache License 2.0 | 5 votes |
private void showPopupWindow() { //创建对象 PopupWindow popupWindow = new PopupWindow(this); View inflate = LayoutInflater.from(this).inflate(R.layout.view_pop_custom, null); //设置view布局 popupWindow.setContentView(inflate); popupWindow.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT); popupWindow.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT); //设置动画的方法 popupWindow.setAnimationStyle(R.style.BottomDialog); //设置PopUpWindow的焦点,设置为true之后,PopupWindow内容区域,才可以响应点击事件 popupWindow.setTouchable(true); //设置背景透明 popupWindow.setBackgroundDrawable(new ColorDrawable(0x00000000)); //点击空白处的时候让PopupWindow消失 popupWindow.setOutsideTouchable(true); // true时,点击返回键先消失 PopupWindow // 但是设置为true时setOutsideTouchable,setTouchable方法就失效了(点击外部不消失,内容区域也不响应事件) // false时PopupWindow不处理返回键,默认是false popupWindow.setFocusable(false); //设置dismiss事件 popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { } }); boolean showing = popupWindow.isShowing(); if (!showing){ //show,并且可以设置位置 popupWindow.showAsDropDown(mTv1); } //popupWindow.dismiss(); }
Example 13
Source File: WarningHolder.java From alpha-wallet-android with MIT License | 5 votes |
private void showPopup(View view, WarningData data) { LayoutInflater inflater = LayoutInflater.from(getContext()); View popupView = inflater.inflate(R.layout.popup_remind_later, null); int width = LinearLayout.LayoutParams.WRAP_CONTENT; int height = LinearLayout.LayoutParams.WRAP_CONTENT; final PopupWindow popupWindow = new PopupWindow(popupView, width, height, true); popupView.setOnClickListener(v -> { data.callback.remindMeLater(data.wallet); popupWindow.dismiss(); }); popupWindow.showAsDropDown(view, 0, 20); }
Example 14
Source File: NewSettingsFragment.java From alpha-wallet-android with MIT License | 5 votes |
private void showPopup(View view, String walletAddress) { LayoutInflater inflater = LayoutInflater.from(getContext()); View popupView = inflater.inflate(R.layout.popup_remind_later, null); int width = LinearLayout.LayoutParams.WRAP_CONTENT; int height = LinearLayout.LayoutParams.WRAP_CONTENT; final PopupWindow popupWindow = new PopupWindow(popupView, width, height, true); popupView.setOnClickListener(v -> { viewModel.setIsDismissed(walletAddress, true).subscribe(this::backedUp); popupWindow.dismiss(); }); popupWindow.showAsDropDown(view, 0, 0); }
Example 15
Source File: CategoryTopicRowViewBinder.java From android-discourse with Apache License 2.0 | 5 votes |
public static void showPopup(View v) { final Context c = v.getContext(); LayoutInflater inflater = LayoutInflater.from(c); TextView contentView = (TextView) inflater.inflate(R.layout.participant_popup_item, null); contentView.setText(v.getTag(R.id.poster_name).toString()); PopupWindow popup = new PopupWindow(c); popup.setContentView(contentView); popup.setOutsideTouchable(true); popup.setWindowLayoutMode(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); popup.setBackgroundDrawable(c.getResources().getDrawable(R.drawable.poster_popup_bg)); popup.showAsDropDown(v); }
Example 16
Source File: PopupWindowCompat.java From letv with Apache License 2.0 | 4 votes |
public void showAsDropDown(PopupWindow popup, View anchor, int xoff, int yoff, int gravity) { popup.showAsDropDown(anchor, xoff, yoff); }
Example 17
Source File: PopupWindowCompat.java From adt-leanback-support with Apache License 2.0 | 4 votes |
@Override public void showAsDropDown(PopupWindow popup, View anchor, int xoff, int yoff, int gravity) { popup.showAsDropDown(anchor, xoff, yoff); }
Example 18
Source File: PopupWindowCompatKitKat.java From adt-leanback-support with Apache License 2.0 | 4 votes |
public static void showAsDropDown(PopupWindow popup, View anchor, int xoff, int yoff, int gravity) { popup.showAsDropDown(anchor, xoff, yoff, gravity); }
Example 19
Source File: HomeActivity.java From Tok-Android with GNU General Public License v3.0 | 4 votes |
@Override public void onMenuClick() { PopupWindow popupWindow = HomeMenuWindow.getHomeMenu(this.getActivity()); popupWindow.showAsDropDown(mMenuLayout, 0, ScreenUtils.dimen2px(this, R.dimen.s_20)); }
Example 20
Source File: PopupWindowUtils.java From LQRWeChat with MIT License | 2 votes |
/** * 得到在指定某个视图外的popupwindow并显示 * * @param contentView popupwindow要显示的视图 * @param width popupwindow的宽度 * @param height popupwindow的高度 * @param anchorView 参考视图 * @param xoff x轴偏移量 * @param yoff y轴偏移量 * @return */ public static PopupWindow getPopupWindowAsDropDown(View contentView, int width, int height, View anchorView, int xoff, int yoff) { PopupWindow popupWindow = getPopupWindow(contentView, width, height); popupWindow.showAsDropDown(anchorView, xoff, yoff); return popupWindow; }