2013-04-18 53 views
5

我有只包含WebView的线性布局。我想要做的就是禁用Webview中的点击,意味着我希望事件被调用与RelativeLayout bg_stepsContainer相关联。我已经使用了android:clickable =“false”这里是代码如何禁用点击WebView?

<RelativeLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:minHeight="30dp" 
        android:layout_marginLeft="5dp" 
        android:layout_marginRight="5dp" 
        android:layout_marginTop="5dp" 
        android:layout_marginBottom="5dp" 
        android:id="@+id/bg_stepsContainer" 
        > 

       <LinearLayout 
        android:id="@+id/stepslcontainer" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentLeft="true" 
        android:layout_alignParentTop="true" 

        android:clickable="false" 
        android:focusable="false" 
        android:focusableInTouchMode="false" > 

        <WebView 
         android:id="@+id/bg_stepsToReproduce" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:clickable="false" 
         android:focusable="false" 
         android:focusableInTouchMode="false" 

         android:textColor="@color/solid_black" /> 

        </LinearLayout> 
        <ImageView 
         android:id="@+id/stepsArrow" 
         android:layout_width="10dp" 
         android:layout_height="10dp" 
         android:layout_alignParentRight="true" 
         android:clickable="false" 
         android:layout_marginRight="10dp" 
         android:layout_marginLeft="10dp" 
         android:layout_centerVertical="true" 
         android:src="@drawable/ic_right_arrow" /> 

</RelativeLayout> 

任何建议areappreciated!

+0

也许这可以帮助你http://stackoverflow.com/questions/4415528/how-to-pass-the-onclick-event-to-its-parent-on-android –

+0

http://stackoverflow.com/questions/3853794/disable-webview-touch-events-in-android这将有帮助 –

回答

20
mWebView.setOnTouchListener(new View.OnTouchListener() { 
    @Override 
    public boolean onTouch(View v, MotionEvent event) { 
     return true; 
    } 
}); 

使用android:clickable =“false”不禁用触摸事件。

+0

再次如何启用触摸事件先生请帮助我.. –

+0

@GowthamanM只是从web视图中删除'OnTouchListener'。 – ubuntudroid