PopupWindow 遇到问题

发布于 2024-10-06 23:54:33 字数 895 浏览 0 评论 0 原文

我刚刚开始学习编写 Android 应用程序的教程。我的第一个应用程序希望非常简单,但下一步我遇到了一些麻烦。我的主 GUI 正在运行,它是一个简单的 LinearLayout,其中有几个垂直排列的按钮。当我单击“连接”按钮时,我希望出现一个 PopupWindow,其中包含以下信息:

TextView: "Enter IP Address"
EditText: <ip address should get entered here>
Button:   "OK" --> connects to a PC listening for requests

问题是,当创建 PopupWindow 时,我几乎看不清 TextView 中的任何文本,但它确实存在。更奇怪的是,我看不到 EditText 或 Button。就好像 PopupWindow 正在淡入视图中,但在中途被冻结。

我使用了 this 中的代码回答 SO 让 PopupWindow 正常工作。

一旦 PopupWindow(某种程度)显示,我的应用程序就会被冻结,因为它此时遮挡了主 GUI。

我还添加了对 showAsDropDown() 和 Dismiss() 的调用,当我这样做时,PopupWindow 肯定会消失,因为我在主 GUI 中重新获得了响应能力。

谁能解释一下这是怎么回事?

以下是我所说的关于几乎不可见的 TextView:

alt text

I'm just starting to go through tutorials for writing Android apps. My first app is hopefully going to be very simple, but I am having a little trouble with the next step. I have my main GUI working, which is a simple LinearLayout with several Buttons arranged vertically. When I click on the Connect button, I want a PopupWindow to appear, with the following information:

TextView: "Enter IP Address"
EditText: <ip address should get entered here>
Button:   "OK" --> connects to a PC listening for requests

The problem is, when the PopupWindow is created, I can barely make out any of the text in the TextView, but it's definitely there. More strangely, I can't see the EditText or the Button. It's almost as if the PopupWindow is fading into view, but gets frozen partway.

I used the code from this answer on SO for getting the PopupWindow to (kind of) work.

Once the PopupWindow (kind of) displays, my app is frozen because it's obscuring the main GUI at that point.

I have also added calls to showAsDropDown() and dismiss(), and when I do this the PopupWindow definitely disappears because I regain responsiveness in my main GUI.

Can anyone explain what's going on here?

Here's what I am talking about regarding the barely-visible TextView:

alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

缱倦旧时光 2024-10-13 23:54:33

它绝对必须是 PopupWindow 吗?自定义Dialog可以代替吗?您可以指定自己的布局和布局。按钮等。此处此处此处

Does it absolutely have to be a PopupWindow? Would a custom Dialog do instead? You can specify your own layout & buttons etc. Some examples using custom dialogs are here, here and here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文