मुझे पता है कि यह देर हो चुकी है लेकिन मुझे पता है कि लोगों को अभी भी पॉपअप विंडो के साथ कोई समस्या है। मैंने एक पूरी तरह से काम करने वाला उदाहरण लिखने का फैसला किया है जहां आप पॉपअप विंडो को इसके बाहर छूकर या क्लिक करके या विंडो को स्वयं स्पर्श करके खारिज कर सकते हैं।
PopupWindow.class
public class PopupWindow extends android.widget.PopupWindow
{
Context ctx;
Button btnDismiss;
TextView lblText;
View popupView;
public PopupWindow(Context context)
{
super(context);
ctx = context;
popupView = LayoutInflater.from(context).inflate(R.layout.popup, null);
setContentView(popupView);
btnDismiss = (Button)popupView.findViewById(R.id.btn_dismiss);
lblText = (TextView)popupView.findViewById(R.id.text);
setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
// Closes the popup window when touch outside of it - when looses focus
setOutsideTouchable(true);
setFocusable(true);
// Removes default black background
setBackgroundDrawable(new BitmapDrawable());
btnDismiss.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
dismiss();
}});
// Closes the popup window when touch it
/* this.setTouchInterceptor(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE) {
dismiss();
}
return true;
}
}); */
} // End constructor
// Attaches the view to its parent anchor-view at position x and y
public void show(View anchor, int x, int y)
{
showAtLocation(anchor, Gravity.CENTER, x, y);
}
}
अब पॉप अप विंडो के लिए लेआउट बनाने के लिए:: popup.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:orientation="vertical"
android:padding="10dp" >
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dp"
android:text="PopupWindow Example"
android:textColor="#000000"
android:textSize="17sp"
android:textStyle="italic" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">
<Button
android:id="@+id/btn_dismiss"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dismiss"
android:visibility="gone" />
<TextView
android:id="@+id/lbl_dismiss"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Touch outside of this box to dismiss"
android:textColor="#ffffff"
android:textStyle="bold" />
</FrameLayout>
तो एक नया PopupWindow वर्ग इस कोड को बना सकते हैं और कॉपी कर सकता हूँ करने के लिए
आपकी मुख्य गतिविधि में एक उदाहरण बनाएं PopupWindow वर्ग:
final PopupWindow popupWindow = new PopupWindow(this);
popupWindow.show(findViewById(R.id.YOUR_MAIN_LAYOUT), 0, -250);
जहां YOUR_MAIN_LAYOUT जिसमें popupWindow पॉप अप होगा
स्रोत
2012-09-29 19:01:16
लेकिन यह एक संवाद नहीं है, हालांकि यह पॉपअपविंडो – lorraine
है, मैंने इसे याद किया है। क्या आप अपने पॉपअपविंडो पर सेटबैकग्राउंड ड्रायबल का उपयोग कर रहे हैं? मुझे पता है कि नट को खींचने योग्य पृष्ठभूमि को ऑनटचलिस्टर –
को मारता है आपको यह मिल गया। पृष्ठभूमि को हटाने योग्य काम करता है। आप अपना उत्तर संपादित करना चाहेंगे, इसलिए मैं इसे स्वीकार किए जाने के रूप में चिह्नित कर सकता हूं। :) धन्यवाद मित्र। – lorraine