简体   繁体   English

Android:弹出对话框样式窗口

[英]Android: a pop-up dialog style window

Right now I have a popupWindow being dynamically populated with a check-list. 现在,我有一个popupWindow用检查表动态填充。 This window pops up when the user taps the check-list button on screen. 当用户点击屏幕上的清单按钮时,将弹出此窗口。

However, the items in the background are not being faded out and they seem are still click-able. 但是,背景中的项目并未淡出,它们似乎仍然可以单击。

I've tried Dialog.Builder but those windows are instantly dismissed when the user taps outside the range of the check-list. 我已经尝试过Dialog.Builder,但是当用户在检查列表的范围之外点击时,这些窗口将立即关闭。

so right now I have 所以现在我有

PopupWindow newPop = new PopupWindow(ActionBar.LayoutParams.MATCH_PARENT,ActionBar.LayoutParams.WRAP_CONTENT);

That is generating the popup. 那正在产生弹出窗口。

Then there is my root element for the popup. 然后是弹出窗口的根元素。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/shadow"
android:layout_gravity="center"
android:gravity="center"
android:id="@+id/TopChecklist"> generating check-list here </LinearLayout>

So, can anyone recommend a way for the background to be un-touchable and to be faded? 因此,有人可以推荐一种使背景不可触摸且褪色的方法吗?

EDIT: Nevermind, I found a trick to get around it. 编辑:没关系,我找到了解决它的技巧。 I changed the layout_width to fill_parent under the XML Then I changed 我将XML下的layout_width更改为fill_parent,然后更改了

android:background="@drawable/shadow"

To a rectangle object with color value #88000000 到颜色值为#88000000的矩形对象

Now the buttons in the background can't be tapped and it all looks faded 现在,无法点击背景中的按钮,并且它们看上去都已褪色

Floor is still open for anyone that has a better way of doing it. 地板仍然开放给任何有更好方法的人。

An AlertDialog should do the trick. AlertDialog应该可以解决问题。 Refer to: http://www.mkyong.com/android/android-custom-dialog-example/ 请参阅: http : //www.mkyong.com/android/android-custom-dialog-example/

I don't know if I understand your question right, but you could use a normal Dialog like this: 我不知道我是否正确理解您的问题,但是您可以使用像这样的普通对话框:

public void ShowMyDialog() { 
    Dialog myDialog = new Dialog(context);
    myDialog.setContentView(R.layout.MyLayout);

and use: 并使用:

myDialog.setCanceledOnTouchOutside(false);  //Dialog not cancelable when clicked outside dialog

or 要么

myDialog.setCancelable(false); //Dialog not cancelable with back key

and dynamically at your checklist... 并动态地在您的清单...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM