pro*_*m85 16 android popupwindow android-popupwindow
我使用以下代码来显示一个小弹出窗口:
public static PopupWindow showImportMenu(Activity activity, View anchor, PopupWindowClickListener onClickListener)
{
LayoutInflater inflater = LayoutInflater.from(activity);
PopupImportBinding binding = DataBindingUtil.inflate(inflater, R.layout.popup_import, null, false);
if (!RootTools.isRootAvailable())
binding.llImportRootMethod.setVisibility(View.GONE);
PopupWindow popupWindow = new PopupWindow(activity, null, R.attr.popupMenuStyle);
popupWindow.setFocusable(true);
popupWindow.setContentView(binding.getRoot());
popupWindow.setOutsideTouchable(true);
PopupWindowCompat.showAsDropDown(popupWindow, anchor, 0, 0, Gravity.BOTTOM);
View.OnClickListener clickListener = new View.OnClickListener()
{
@Override
public void onClick(View view)
{
onClickListener.onClick(popupWindow, view);
}
};
binding.llImportDefault.setOnClickListener(clickListener);
binding.llImportRootMethod.setOnClickListener(clickListener);
binding.llImportHTCFromContacts.setOnClickListener(clickListener);
binding.llImportManual.setOnClickListener(clickListener);
return popupWindow;
}
Run Code Online (Sandbox Code Playgroud)
这适用于很多设备,但在一些罕见的设备上它不起作用,如:
我收到的反馈是没有显示弹出窗口.有谁知道为什么这不适用于上述设备?我能做些什么才能让它在这个设备上运行?
编辑
似乎我不想清楚我想要的是:
showAsDropDown没有showAtLocation或类似的,我从来没有看到这个问题showAtLocation还没有BottomSheet对我来说很好,但我仍然想知道问题是否可以解决并以某种方式处理在运行5.1.1的Nexus 7(不是2012)上,我遇到了同样的问题。最后通过添加以下行来修复它:
popupWindow.setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
Run Code Online (Sandbox Code Playgroud)
## 好吧,我实现了弹出窗口,用于在我的选项卡片段中进行排序,并且我检查过一次尝试后工作正常
final PopupWindow popupWindow = new PopupWindow(getActivity());
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.popmenu1t1, null);
l8[![enter image description here][1]][1] = (LinearLayout) view.findViewById(R.id.atoz);
l8.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
date_sort="0";
discount_sort="";
price_sort="";
alpha_sort="";
popupWindow.dismiss();
}
});
int width = 900;
int height = 400;
try {
WindowManager wm = (WindowManager)view.getContext().getSystemService(Context.WINDOW_SERVICE);
width = wm.getDefaultDisplay().getWidth();
height = wm.getDefaultDisplay().getHeight();
} catch (Exception e) {
e.printStackTrace();
}
popupWindow.setWidth(width*3/6);
popupWindow.setFocusable(true);
popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
popupWindow.setContentView(view);
popupWindow.setBackgroundDrawable(null);
popupWindow.setOutsideTouchable(true);
popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1801 次 |
| 最近记录: |