我使用以下代码来显示一个小弹出窗口:
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还没有 …我正在创建一个新窗口,其中包含用户将要打印的文本.我想做类似的事情:
var new_win = window.open();
$(new_win.document).html("Test");
Run Code Online (Sandbox Code Playgroud) 我有一个PopupWindow,在用户输入EditText时显示.这个弹出窗口为他提供了一些建议.我的问题是,当弹出窗口显示时,它的一部分显示在屏幕上的键盘上,阻止用户继续键入.有谁知道这种行为的原因,我该如何解决?
在针对a的Android文档中PopupWindow,setIgnoreCheekPress()提到了该方法.它说这个方法"设置弹出窗口上的标志来忽略脸颊按压事件;默认情况下,这个标志设置为false,这意味着流行音乐不会忽略脸颊按发送事件."
很简单,什么是cheek press dispatch event?
我正在尝试制作一个简单的弹出窗口.但是每次我制作一个,它最终都会变得非常小......而不是我想要它的长度.这是弹出窗口的样子:

这是弹出窗口的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/popup_element"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#444444"
android:padding="10px"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Transfering data"
android:textColor="@color/white"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Status"
android:textColor="@color/white"/>
<TextView android:id="@+id/server_status_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Awaiting answer..."
android:paddingLeft="10sp"
android:textColor="@color/white"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:gravity="center_horizontal|bottom">
<Button android:id="@+id/end_data_send_button"
android:layout_width="100dp"
android:layout_height="100dp"
android:drawablePadding="3sp"
android:layout_centerHorizontal="true"
android:text="Cancel" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是我的java代码:
private PopupWindow pw;
private void bindActivity() {
fabButton = (ImageButton) findViewById(R.id.activity_profileView_FAB);
fabButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
initiatePopupWindow();
}
});
}
private void initiatePopupWindow() {
try …Run Code Online (Sandbox Code Playgroud) 我想要一个完全自定义的Dialog或PopupWindow,没有任何默认的Android UI控件(标题,背景,按钮等等).
这有可能吗?我花了几个小时寻找这个,但没有运气......看起来这应该很容易,但我找不到它.
最好是通过从XML中扩展View,但此时任何可行的东西都会很好.
谢谢.
我正在使用Java在Android 2.2上进行开发.我在PopupWindow上放了一个editText,它不起作用.它就像一个禁用的编辑文本,单击编辑文本将不会显示软键盘.如何在popupWindow上添加编辑文本?
我正在使用PopupWindow和showAsDropDown(锚).当锚点位于屏幕顶部时,它可以正常工作,但是当屏幕底部没有显示任何内容时.根据PopupWindow.showAsDropDown()的文档,这应该工作:
"在锚定到锚点视图左下角的弹出窗口中显示内容视图.如果屏幕上没有足够的空间来显示整个弹出窗口,则此方法会尝试查找要滚动的父卷轴视图.没有父滚动视图可以滚动,弹出窗口的左下角固定在锚点视图的左上角."
据推测,弹出窗口始终锚定在锚点视图的左下角.我该如何解决?
我有一个PopupWindow,我希望它在用户触摸外面时解散,所以我调查并发现我必须使用它popup.setBackgroundDrawable(new BitmapDrawable());.问题new BitmpaDrawable()是不推荐使用构造函数.我想在不使用它的情况下找到解决方案.
谁知道怎么解决这个问题?
谢谢!
final PopupWindow popup = new PopupWindow(sortByView,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
true);
popup.setBackgroundDrawable(new BitmapDrawable());
popup.setOutsideTouchable(true);
popup.showAsDropDown(v);
Run Code Online (Sandbox Code Playgroud) 我正在制作一个显示popupWindow语言的键盘。在所有设备上,我都可以popupWindow在键盘外完美显示,但在仅Android Pie中,不能popupWindow在键盘外显示。
candidateView连接蓝牙键盘时,我想在键盘之外显示弹出窗口。
我正在使用此代码
setClippingEnabled(false);
showAtLocation(anchor, Gravity.NO_GRAVITY, x, y);
Run Code Online (Sandbox Code Playgroud)
有人有什么想法吗,这是什么问题?
这是演示应用程序-https: //github.com/priyankagb/andoidpiepopupwindowdemo
看截图
在Android Pie中,您可以在底部看到一小行popupWindow用于语言
左边是馅饼下方,右边是馅饼

popupwindow ×10
android ×9
java ×3
dialog ×1
flags ×1
javascript ×1
jquery ×1
keyboard ×1
methods ×1
skinning ×1