How to open a PopupWindow on Android and let all the others components touchable without dismiss the PopupWindow?
This is how it's created:
public class DynamicPopup {
private final PopupWindow window;
private final RectF rect;
private final View parent;
private final RichPageView view;
public DynamicPopup(Context context, RichPage page, RectF rectF, View parent) {
this.parent = parent;
rect = rectF;
window = new PopupWindow(context);
window.setBackgroundDrawable(new BitmapDrawable());
window.setWidth((int) rect.width());
window.setHe开发者_如何转开发ight((int) rect.height());
window.setTouchable(true);
window.setFocusable(true);
window.setOutsideTouchable(true);
view = new RichPageView(context, page, false);
window.setContentView(view);
view.setOnCloseListener(new Listener(){
@Override
public void onAction() {
window.dismiss();
}
});
}
public void show() {
window.showAtLocation(parent, Gravity.NO_GRAVITY, (int) rect.left, (int) rect.top);
}
}
just like the ernazm say
As per javadocs
Controls whether the pop-up will be informed of touch events outside of its window. This only makes sense for pop-ups that are touchable but not focusable
and it's work on
window.setTouchable(true);
window.setFocusable(false);
window.setOutsideTouchable(false);
When window touchalbe is true, focusable is false, setOutsideTouchable() is work, if setOutsideTouchable(true), touch outside of popupwindow will dismiss, otherwise the outside of popupwindows still can be touchable without dismiss.
As per javadocs
Controls whether the pop-up will be informed of touch events outside of its window. This only makes sense for pop-ups that are touchable but not focusable
So your line
window.setFocusable(true);
causes the method setOutsideTouchable()
to do nothing.
For that you have to made the Custom Popup window. In that u have to call the another layout. So in this way You can access the other component also. It just the One type of the Layout. But you can set its appearence as Popup Window.
<!-- POPUP MENU -->
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/popup_window"
android:orientation="vertical"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/fullwindowborderforpopup"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="1px"
android:layout_marginTop="15dip"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:layout_marginBottom="10dip"
android:background="@drawable/borderforpopup"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginTop="5dip"
android:layout_marginLeft="3dip"
android:layout_marginRight="3dip"
android:layout_marginBottom="3dip">
<TextView
android:id="@+id/tital_of_popup"
android:gravity="center_vertical|center_horizontal"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Event Registration"
android:textStyle="bold"
android:textColor="#ffffff"
/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginTop="5dip"
android:layout_marginLeft="3dip"
android:layout_marginRight="3dip"
android:layout_marginBottom="3dip"
>
<TextView
android:id="@+id/message_of_popup"
android:gravity="center_vertical|center_horizontal"
android:layout_height="wrap_content"
android:text="Please fill all the data"
android:layout_width="wrap_content"
android:textStyle="normal"
android:textColor="#ffffff" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginTop="5dip"
android:layout_marginLeft="6dip"
android:layout_marginRight="6dip"
android:layout_marginBottom="9dip"
>
<Button
android:layout_height="fill_parent"
android:id="@+id/okbutton"
android:text="OK"
android:textColor="#ffffff"
android:shadowColor="#000000"
android:gravity="center"
android:layout_width="fill_parent"
android:background="@drawable/buttonborderframe"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
try this. And you can hide and show the layout whenever you want. And other fields are accessable.
Try adding this to your code:
window.setOutsideTouchable(true);
From the Android documentation:
void setOutsideTouchable (boolean touchable)
Controls whether the pop-up will be informed of touch events outside of its window. This only makes sense for pop-ups that are touchable but not focusable, which means touches outside of the window will be delivered to the window behind. The default is
false
.If the popup is showing, calling this method will take effect only the next time the popup is shown or through a manual call to one of the
update()
methods.
精彩评论