本文整理汇总了Java中android.widget.PopupWindow.showAsDropDown方法的典型用法代码示例。如果您正苦于以下问题:Java PopupWindow.showAsDropDown方法的具体用法?Java PopupWindow.showAsDropDown怎么用?Java PopupWindow.showAsDropDown使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.PopupWindow
的用法示例。
在下文中一共展示了PopupWindow.showAsDropDown方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createPopupWindow
import android.widget.PopupWindow; //导入方法依赖的package包/类
/**
* 创建PopupWindow选择提示框
*
* @param activity 当前Activity
* @param targetView 与提示框关联的控件
* @param width 提示框宽
* @param height 提示框高
*/
private static void createPopupWindow(Activity activity, View targetView,
int width, int height) {
popupWindowDismiss();
//通过布局注入器,注入布局给View对象
if (view != null) {
view = null;
}
view = activity.getLayoutInflater().inflate(R.layout.layout_popup_window, null);
//通过view和宽·高,构造popupWindow
popupWindow = new PopupWindow(view, width, height);
popupWindow.setFocusable(true);
//popupWindow.setBackgroundDrawable(new BitmapDrawable());
//设置window视图的位置
popupWindow.showAsDropDown(targetView);
}
示例2: test
import android.widget.PopupWindow; //导入方法依赖的package包/类
private void test(){
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View contentview = inflater.inflate(R.layout.pop_layout1, null);
final PopupWindow popupWindow = new PopupWindow(contentview, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
//popupWindow
popupWindow.setFocusable(true);
popupWindow.setOutsideTouchable(false);
popupWindow.setBackgroundDrawable(null);
popupWindow.getContentView().setFocusable(true); // 这个很重要
popupWindow.getContentView().setFocusableInTouchMode(true);
popupWindow.getContentView().setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
popupWindow.dismiss();
return true;
}
return false;
}
});
popupWindow.showAsDropDown(mButton1, 0, 10);
}
示例3: show
import android.widget.PopupWindow; //导入方法依赖的package包/类
private void show() {
RecyclerView recyclerView = new RecyclerView(getContext());
recyclerView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
recyclerView.setAdapter(adapter);
popupWindow = new PopupWindow(recyclerView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
popupWindow.showAsDropDown(this);
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
if (onItemSelectedListener != null) {
onItemSelectedListener.onNothingSelected();
}
dismiss();
}
});
}
示例4: showReactionPopup
import android.widget.PopupWindow; //导入方法依赖的package包/类
private void showReactionPopup(View anchorView) {
ReactionView layout = new ReactionView(MainActivity.this, this);
int width = LinearLayout.LayoutParams.MATCH_PARENT;
int height = LinearLayout.LayoutParams.WRAP_CONTENT;
boolean focusable = true;
popupWindow = new PopupWindow(layout, width, height, focusable);
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
popupWindow.setTouchable(true);
if (popupWindow != null && popupWindow.isShowing()) {
popupWindow.dismiss();
} else {
// if (android.os.Build.VERSION.SDK_INT >= 24) {
// int[] a = new int[2];
// anchorView.getLocationInWindow(a);
// popupWindow.showAtLocation(getWindow().getDecorView(), Gravity.NO_GRAVITY, 0, a[1] - (anchorView.getHeight() + DisplayUtil.dpToPx(8)));
// } else {
popupWindow.showAsDropDown(anchorView, 0, -DisplayUtil.dpToPx(anchorView.getHeight() + DisplayUtil.dpToPx(8)));
// }
}
}
示例5: showWebViewOpWindow
import android.widget.PopupWindow; //导入方法依赖的package包/类
/**
* 显示PopupWindow:WebView操作
*
* @param view
*/
private void showWebViewOpWindow(View view) {
View contentView = getLayoutInflater().inflate(R.layout.window_webview_op, null);
// 设置Item的点击事件
LinearLayout llRefresh = (LinearLayout) contentView.findViewById(R.id.llRefresh);
LinearLayout llCopyUrl = (LinearLayout) contentView.findViewById(R.id.llCopyUrl);
LinearLayout llOpen = (LinearLayout) contentView.findViewById(R.id.llOpen);
final PopupWindow popupWindow = new PopupWindow(contentView,
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT, true);
OpClickListener listener = new OpClickListener(popupWindow);
llRefresh.setOnClickListener(listener);
llCopyUrl.setOnClickListener(listener);
llOpen.setOnClickListener(listener);
// 如果不设置PopupWindow的背景,无论是点击外部区域还是Back键都无法dismiss弹框
popupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.popup_transparent_bg));
// 设置好参数之后再show
popupWindow.showAsDropDown(view);
}
示例6: getPopupWindowAsDropDownParentAuto
import android.widget.PopupWindow; //导入方法依赖的package包/类
/**
* 得到一个自动识别在目标控件上方或下方的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;
}
示例7: popupShow
import android.widget.PopupWindow; //导入方法依赖的package包/类
/**
* 显示popup window
*
* @param view popup window
*/
private void popupShow(View view) {
int density = (int) ScreenUtil.getDeviceDensity(this);
//显示popup window
mPopupWindow = new PopupWindow(mPopupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
mPopupWindow.setFocusable(true);
mPopupWindow.setOutsideTouchable(true);
//透明背景
Drawable transparent = new ColorDrawable(Color.TRANSPARENT);
mPopupWindow.setBackgroundDrawable(transparent);
//获取位置
int[] location = new int[2];
view.getLocationOnScreen(location);
mPopupWindow.showAsDropDown(view, 0, 0);
}
示例8: initmPopupWindowFunctionListView
import android.widget.PopupWindow; //导入方法依赖的package包/类
/**
* 编辑页功能清单
* 提醒、清单、发送、查找、详情、删除
*/
private void initmPopupWindowFunctionListView() {
View customView = getLayoutInflater().inflate(R.layout.item_note_edit_popup, null, false);
// 创建PopupWindow实例,设置宽度和高度
FunctionPopup = new PopupWindow(customView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
FunctionPopup.setAnimationStyle(R.style.AnimationFade);
FunctionPopup.showAsDropDown(customView);
customView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (FunctionPopup != null && FunctionPopup.isShowing()) {
FunctionPopup.dismiss();
FunctionPopup = null;
}
return false;
}
});
TextView tv_note_remind = (TextView) customView.findViewById(R.id.tv_note_remind);
TextView tv_note_list = (TextView) customView.findViewById(R.id.tv_note_list);
TextView tv_note_send = (TextView) customView.findViewById(R.id.tv_note_send);
TextView tv_note_select = (TextView) customView.findViewById(R.id.tv_note_select);
TextView tv_note_detail = (TextView) customView.findViewById(R.id.tv_note_detail);
TextView tv_note_delete = (TextView) customView.findViewById(R.id.tv_note_delete);
tv_note_remind.setOnClickListener(this);
tv_note_list.setOnClickListener(this);
tv_note_send.setOnClickListener(this);
tv_note_select.setOnClickListener(this);
tv_note_detail.setOnClickListener(this);
tv_note_delete.setOnClickListener(this);
}
示例9: showTip
import android.widget.PopupWindow; //导入方法依赖的package包/类
public PopupWindow showTip(View anchorView, String txt) {
final View contentView = LayoutInflater.from(anchorView.getContext()).inflate(R.layout.popup_empty_content_layout, null);
if (txt != null) {
TextView tipTv = (TextView) contentView.findViewById(R.id.toast_txt_tv);
tipTv.setText(txt);
}
final PopupWindow popupWindow = new PopupWindow(contentView,
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
popupWindow.setAnimationStyle(R.style.PopupAnimation);
popupWindow.setTouchable(false);
popupWindow.showAsDropDown(anchorView);
return popupWindow;
}
示例10: 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);
}
}
示例11: showStatusOpWindow
import android.widget.PopupWindow; //导入方法依赖的package包/类
/**
* 显示微博操作PopupWindow
*
* @param view
* @param retweeted 是否有原微博
*/
private void showStatusOpWindow(View view, long statusId, String statusText, boolean retweeted,
long retweetedStatusId, boolean favorited, int position, String screenName) {
View contentView = LayoutInflater.from(mActivity).inflate(
R.layout.window_status_op, null);
// 设置Item的点击事件
View divider_1 = contentView.findViewById(R.id.divider_1);
TextView tvMark = (TextView) contentView.findViewById(R.id.tvMark);
if (favorited) {
tvMark.setText(R.string.unmark_status);
} else {
tvMark.setText(R.string.mark_status);
}
LinearLayout llRetweetedStatus = (LinearLayout) contentView.findViewById(R.id.llRetweetedStatus);
LinearLayout llMarkStatus = (LinearLayout) contentView.findViewById(R.id.llMarkStatus);
LinearLayout llShareStatus = (LinearLayout) contentView.findViewById(R.id.llShareStatus);
LinearLayout llCopyStatus = (LinearLayout) contentView.findViewById(R.id.llCopyStatus);
if (retweeted) {
llRetweetedStatus.setVisibility(View.VISIBLE);
divider_1.setVisibility(View.VISIBLE);
} else {
llRetweetedStatus.setVisibility(View.GONE);
divider_1.setVisibility(View.GONE);
}
final PopupWindow popupWindow = new PopupWindow(contentView,
ScrollView.LayoutParams.WRAP_CONTENT, ScrollView.LayoutParams.WRAP_CONTENT, true);
OpClickListener listener;
if (retweeted) {
listener = new OpClickListener(popupWindow, statusId, statusText, retweetedStatusId,
favorited, position, screenName);
} else {
listener = new OpClickListener(popupWindow, statusId, statusText, 0L, favorited,
position, screenName);
}
llRetweetedStatus.setOnClickListener(listener);
llMarkStatus.setOnClickListener(listener);
llShareStatus.setOnClickListener(listener);
llCopyStatus.setOnClickListener(listener);
// 如果不设置PopupWindow的背景,无论是点击外部区域还是Back键都无法dismiss弹框
popupWindow.setBackgroundDrawable(mActivity.getResources().getDrawable(R.drawable.popup_transparent_bg));
// 设置好参数之后再show
popupWindow.showAsDropDown(view);
}
示例12: showLongPressEmojiTip
import android.widget.PopupWindow; //导入方法依赖的package包/类
private void showLongPressEmojiTip() {
PopupWindow popupWindow = new PopupWindow(getContext());
popupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setContentView(LayoutInflater.from(getContext()).inflate(R.layout.layout_bubble, null));
popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
popupWindow.setOutsideTouchable(true);
popupWindow.showAsDropDown(mTextInputEditText, 0, 30, Gravity.CENTER_HORIZONTAL);
}
示例13: showAsDropDown
import android.widget.PopupWindow; //导入方法依赖的package包/类
public static void showAsDropDown(PopupWindow popup, View anchor, int xoff, int yoff, int gravity) {
popup.showAsDropDown(anchor, xoff, yoff, gravity);
}
示例14: getPopupWindowAsDropDown
import android.widget.PopupWindow; //导入方法依赖的package包/类
/**
* 得到在指定某个视图外的popupwindow并显示(该方法只支持4.4以上)
*
* @param contentView popupwindow要显示的视图
* @param width popupwindow的宽度
* @param height popupwindow的高度
* @param anchorView 参考视图
* @param gravityType 在参考视图外的相对位置
* @param xoff x轴偏移量
* @param yoff y轴偏移量
* @return
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
public static PopupWindow getPopupWindowAsDropDown(View contentView, int width, int height, View anchorView, int gravityType, int xoff, int yoff) {
PopupWindow popupWindow = getPopupWindow(contentView, width, height);
popupWindow.showAsDropDown(anchorView, xoff, yoff, gravityType);
return popupWindow;
}