2014-12-18 2 views
0

나는 지금 webview에 있는데, 나는 웹뷰에서 팝업 창을 보여 주려고 고심하고있다. 내가 만졌을 때마다 내가 터치 한 똑같은 위치에서 webview를 터치 할 때마다 팝업 창을 표시해야합니다. ontouchlistener를 시도했지만 여전히 팝업보기를 사용할 수 없습니다. 너희들이 내가이 문제를 해결하도록 도울 수 있겠 니? 미리 감사드립니다. 아래는 제 코드입니다.android의 webview에서 screentouch의 팝업 창을 표시하는 방법?

webView.setOnTouchListener(new OnTouchListener() { 

    @Override 
    public boolean onTouch(View v, MotionEvent event) { 

     switch (event.getAction() & MotionEvent.ACTION_MASK) { 
     case MotionEvent.ACTION_DOWN: 
      touch(); 
      break; 
     case MotionEvent.ACTION_POINTER_DOWN: 
      touch(); 
      break; 
     case MotionEvent.ACTION_MOVE: 
      touch(); 
      break; 
     case MotionEvent.ACTION_UP: 
      touch(); 
      break; 
     case MotionEvent.ACTION_POINTER_UP: 
      touch(); 
      break; 
     } 
     return true; 
    } 
}); 

public void touch() { 
    View popUpView = getLayoutInflater().inflate(R.layout.popup, null);                   
    mpopup = new PopupWindow(popUpView, LayoutParams.FILL_PARENT, 
     LayoutParams.WRAP_CONTENT, true); 
    mpopup.setAnimationStyle(android.R.style.Animation_Dialog); 
    mpopup.showAtLocation(popUpView, Gravity.NO_GRAVITY, 0, 0); 

    Button option = (Button) popUpView.findViewById(R.id.sign); 
    option.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      mpopup.dismiss(); 
      Intent intent = new Intent(View.this, 
       Capture.class); 
      startActivity(intent); 
      finish(); 
     } 
    }); 
    Button btnOk = (Button) popUpView.findViewById(R.id.date); 
    btnOk.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      mpopup.dismiss(); 
     } 
    }); 

웹 뷰를 터치하면 앱이 다운됩니다.

popup.xml

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:orientation="vertical" 
    android:background="@android:color/transparent" 
    android:layout_height="wrap_content"> 

    <Button 
     android:id="@+id/sign" 
     android:layout_width="160dp" 
     android:layout_height="60dp" 
     android:layout_toLeftOf="@+id/camera" 
     android:text="button" > 
    </Button> 

    <Button 
     android:id="@+id/date" 
     android:layout_width="160dp" 
     android:layout_height="60dp" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:text="button" /> 

</RelativeLayout> 
+0

당신이 당신의 로그 캣 메시지를 게시 할 수 : 다음

는 웹보기에 OnClickListener를 설정? – SLee

+0

글쎄, 난 그냥 충돌이 어떤 예외가 없었어요. – Vicky

+0

나는 logcat을 사용하여 내 질문을 업데이트 할 예정입니다. – Vicky

답변

0

이 시도 :

LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    mpopup = new PopupWindow(inflater.inflate(R.layout.popup, null, false), 100, 100, true); 

    // Show the Popup 
    mpopup.showAtLocation(this.findViewById(R.id.main), Gravity.CENTER, 0, 0); 

당신 레이아웃 (루트 컨테이너) 예를 들어, ID 세트가 있어야합니다 웹보기로 설정

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:id="@+id/main" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <WebView 
     android:id="@+id/webViewEx1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     /> 


</LinearLayout> 
+0

기다릴 수 있습니까? 작동하는지 알려 드리겠습니다. – Vicky

+0

코드에서 NullPointerException이 발생했습니다. @ mpopup.showAtLocation (this.findViewById (R.id.main), Gravity.CENTER, 0, 0); – Vicky

+0

레이아웃에 ID를 추가 했습니까? –

0

android:clickable="true"

귀하의 활동 중 RelativeLayout에 있습니다.

WebView wv = (WebView) findViewById(R.id.webview); 
wv.setOnClickListener(new OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     Intent i = new Intent(getApplicationContext(), NextActivity.class); 
     startActivity(i); 
    } 
}); 
관련 문제