当前位置: 首页 > 知识库问答 >
问题:

在Android应用程序中打开弹出窗口时出现异常

洪浩
2023-03-14

我在尝试调用此方法时遇到以下异常。

MessageQueue回调中出现异常:HandlerReceiveCallback 08-21 00:12:43.454 10843-10843/common。以货换货通用域名格式。barterapp E/MessageQueue JNI﹕ Android看法膨胀异常:二进制XML文件行#2:在android上inflating类时出错。看法更平坦。com上的createView(LayoutInflater.java:633)。Android内部的政策impl。电话更平。android上的onCreateView(PhoneLayoutInflater.java:55)。看法更平坦。android上的onCreateView(LayoutInflater.java:682)。看法更平坦。在android上创建ViewFromTag(LayoutInflater.java:741)。看法更平坦。在android上充气(LayoutInflater.java:482)。看法更平坦。在android上充气(LayoutInflater.java:414)。看法更平坦。充气(LayoutInflater.java:365)

public class GlobalHome extends ActionBarActivity{
----------------------
----------------------
private void showLocationPopup() {

    LayoutInflater inflater = (LayoutInflater)
            this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.popup_location,
            (ViewGroup) findViewById(R.id.layout_location_popup));
    PopupWindow pw = new PopupWindow(
            layout,
            100,
            100,
            true);
    // The code below assumes that the root container has an id called 'main'
    pw.showAtLocation(layout, Gravity.CENTER, 0, 0);

}
}

布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:padding="10dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/switch_thumb_material_light"
android:id="@+id/layout_location_popup"
>

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dip"
    android:text="Test Pop-Up"
    />

</LinearLayout>

共有1个答案

穆鸿卓
2023-03-14

将代码更改为:

private void showLocationPopup() {

    LayoutInflater inflater = (LayoutInflater)
            getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.popup_location,(ViewGroup) getActivity().findViewById(R.id.layout_location_popup));
    PopupWindow pw = new PopupWindow(
            layout,
            100,
            100,
            true);
    // The code below assumes that the root container has an id called 'main'
    pw.setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    pw.showAtLocation(layout, Gravity.CENTER, 0, 0);

}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:padding="10dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:id="@+id/layout_location_popup">

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dip"
    android:text="Test Pop-Up"/>
</LinearLayout>

我已经换了颜色,因为你选的那件不起作用。对我来说,这似乎不是典型的android颜色。此外,我还将版面宽度和高度设置为“包裹内容”。对我来说,它现在显示在屏幕中间的白色背景。

 类似资料:
  • 问题内容: 我通过window.open打开了一个弹出窗口。使用JavaScript打开,我想在关闭此弹出窗口时刷新父页面。(onclose事件?)我该怎么办? 问题答案: 您可以使用“ window.opener”访问父窗口,因此,在子窗口中编写如下内容:

  • 问题内容: 我正在尝试使用javafx在webview中打开网页。单击超链接后,此网页将打开一个新的弹出窗口。 我如何打开新的弹出窗口,当尝试在默认Web浏览器(例如chrome,IE)中打开同一网页时,它们正在打开弹出窗口。 为了创建弹出窗口,我使用以下代码。 问题答案: 您需要自己创建WebView弹出窗口,并从回调中提供WebEngine。如果需要新窗口,请使用该WebView创建一个新的舞

  • 问题内容: 我在JPopupMenu中有一个JComboBox(以及其他组件)。事实证明,每当我打开组合框的弹出窗口(以选择一个项目)时,父级JPopupMenu都会关闭。我一直在尝试找到一种方法来覆盖此功能,但无济于事。 有没有人建议防止关闭父级JPopupMenu?谢谢! 问题答案: 这不可能直接实现,很难覆盖已知的错误,另一方面,Swing不允许同时使用两个lightwieght弹出组件 但

  • 我正试图在Mac上安装Eclipse(2018-12),但我得到一个附带的弹出窗口。我已经使用位于home//的sdkman安装了java8。sdkman/candidates/java/8.0。292.j9-adpt 我也尝试过安装Java6,但没有多大帮助。

  • 每当我试图通过启动google登录意图登录时,它都会直接进入onActivityResult,而我没有机会选择帐户。它所做的只是将屏幕变暗,但选择帐户的窗口不会出现。然后登录失败,出现以下异常: 和 (完整堆栈跟踪:https://pastebin.com/vBZeBLu0) 我使用的所有依赖项都是最新的,我的凭据(oAuth客户端id)都设置正确,我尝试了其他类似问题的解决方案,但没有一个解决了

  • 注:本内容不完整。由于安全原因,我不能在这里粘贴完整的JSON