2016-04-12 20 views
0

Ich habe ein WebView mit einem Button davor. Der Button öffnet die URL im externen Browser, die in Android API 21 und höher funktioniert. Aber ich teste auch in API 16, um mehr Geräte zu erreichen. In API API 19 und darunter wird der Button nicht angezeigt, darüber ist der Button sichtbar und funktioniert. Der Button ist nur sichtbar, wenn das WebView eine URL bekommt. Zuvor ist der Button unsichtbar.Button ist nicht sichtbar vor WebView (API 19 und unter ihnen)

mein relevanter Java-Code ist:

public void launchWebViewByURL(String url) 
    { 
     showSpinner(); 
     Button browserButton = (Button) fragmentView.findViewById(R.id.WebViewButton); 
     browserButton.setVisibility(View.VISIBLE); 
     webView.loadUrl(url); 
    } 

mein relevant XMK ist

<RelativeLayout 
     android:id="@+id/WebViewLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     android:layout_above="@+id/statusIndicators" 
     android:layout_below="@+id/statusIndicatorTop"> 

     <Button 
      android:id="@+id/WebViewButton" 
      android:text="@string/webViewButton" 
      android:layout_width="80dp" 
      android:layout_height="50dp" 
      android:textSize="7dp" 
      android:alpha="0.7" 
      android:visibility="invisible" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" 
      android:layout_marginRight="5dp" 
      android:layout_marginBottom="5dp" /> 

     <WebView 
      android:id="@+id/WebView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:requiresFadingEdge="vertical" 
      android:fadingEdgeLength="16dp" 
      android:background="@color/colorPrimary" 
      android:overScrollMode="ifContentScrolls" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentLeft="true" 
      android:visibility="visible" /> 


     <RelativeLayout 
      android:id="@+id/WebViewOverlay" 
      android:layout_width="match_parent" 
      android:layout_height="fill_parent" 
      android:background="@android:color/black" 
      android:visibility="invisible" 
      android:alpha="0.5"> 

      <com.pnikosis.materialishprogress.ProgressWheel 
       android:id="@+id/ProgressWheel" 
       android:layout_width="@dimen/spinner_dimen" 
       android:layout_height="@dimen/spinner_dimen" 
       android:layout_centerHorizontal="true" 
       android:layout_centerVertical="true" 
       wheel:matProg_barColor="@color/colorAccent" 
       wheel:matProg_circleRadius="@dimen/spinner_dimen" 
       wheel:matProg_barWidth="@dimen/spinner_breadth" 
       wheel:matProg_progressIndeterminate="true" 
       /> 

     </RelativeLayout> 

    </RelativeLayout> 

Wenn die WebView eine Alpha wie der Knopf hat, der Knopf ist sichtbar aber nicht anfassbar. Wenn das WebView nicht sichtbar ist, wird der Button angezeigt und funktioniert. Kann mir jemand helfen, den Button in "niedrigeren" APIs wie 19 und darunter nach vorne zu bringen?

Antwort

1

Der Grund, warum Taste nicht berühren hört, weil sein von WebView verbraucht immer als WebView vor Ihrem Knopf ist. Wenn Sie Alpha für WebView ändern, wird es immer noch in ViewGroup gezeichnet (in Ihrem Fall RelativeLayout) und verbraucht alle Berührungsereignisse innerhalb seiner Grenzen. Eine Lösung für Sie ist also, Ihren Button nach vorne zu bringen. Vielleicht lesen Sie Dokumentation für RelativeLayout, um zu wissen, wie es funktioniert.

unten Code sollte

arbeiten
<RelativeLayout 
    android:id="@+id/WebViewLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_above="@+id/statusIndicators" 
    android:layout_below="@+id/statusIndicatorTop"> 

    <WebView 
     android:id="@+id/WebView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/colorPrimary" 
     android:fadingEdgeLength="16dp" 
     android:overScrollMode="ifContentScrolls" 
     android:requiresFadingEdge="vertical" 
     android:visibility="visible"/> 

    <RelativeLayout 
     android:id="@+id/WebViewOverlay" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:alpha="0.5" 
     android:background="@android:color/black" 
     android:visibility="invisible"> 

     <com.pnikosis.materialishprogress.ProgressWheel 
      android:id="@+id/ProgressWheel" 
      wheel:matProg_barColor="@color/colorAccent" 
      wheel:matProg_barWidth="@dimen/spinner_breadth" 
      wheel:matProg_circleRadius="@dimen/spinner_dimen" 
      wheel:matProg_progressIndeterminate="true" 
      android:layout_width="@dimen/spinner_dimen" 
      android:layout_height="@dimen/spinner_dimen" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" 
      /> 

    </RelativeLayout> 

    <Button 
     android:id="@+id/WebViewButton" 
     android:layout_width="80dp" 
     android:layout_height="50dp" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:layout_marginBottom="5dp" 
     android:layout_marginRight="5dp" 
     android:alpha="0.7" 
     android:text="@string/webViewButton" 
     android:textSize="7dp" 
     android:visibility="invisible"/> 
</RelativeLayout> 
+0

Ihr sehr viel Dank, dass mein Problem gelöst. –

0

In einem relativen Layout wird die "z" Reihenfolge der Elemente durch die Reihenfolge definiert, in der diese Elemente zum relativen Layout hinzugefügt wurden. Je niedriger also ein Element im Layout ist, desto höher ist sein z-Wert. Um dies zu sagen, verschieben Sie WebViewButton an den unteren Rand des Layouts, damit es über der Webansicht liegt.

0
try for this 


    <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Enter" 
       android:id="@+id/WebViewButton" 
       /> 

      <WebView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/webView" 
       android:layout_below="@+id/WebViewButton" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:layout_alignParentRight="true" 
       android:layout_alignParentEnd="true" 
       android:layout_alignParentBottom="true" /> 
0
<RelativeLayout 
     android:id="@+id/WebViewLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     > 



     <WebView 
      android:id="@+id/WebView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:requiresFadingEdge="vertical" 
      android:fadingEdgeLength="16dp" 
      android:background="@color/colorPrimary" 
      android:overScrollMode="ifContentScrolls" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentLeft="true" 
      android:visibility="visible" /> 


     <Button 
      android:id="@+id/WebViewButton" 
      android:text="gfjhfgj" 
      android:layout_width="80dp" 
      android:layout_height="50dp" 
      android:textSize="7dp" 
      android:alpha="0.7" 
      android:visibility="visible" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" 
      android:layout_marginRight="5dp" 
      android:layout_marginBottom="5dp" /> 

    </RelativeLayout>