2017-05-26 7 views
0

Ich bin dabei, einen In-App-Browser zu erstellen, der Eingaben von einem Editiertext in einer Symbolleiste verarbeiten kann. Laden Sie dann nach Überprüfung der URL, ob die URL gültig ist gegebene Webseite. Wenn ich das aber tue, stoße ich auf ein Problem, wenn die Symbolleiste vorhanden ist, verweigert die Webansicht das Laden. Wenn die Symbolleiste jedoch nicht vorhanden ist, lädt die Webansicht einwandfrei.Webview wird nicht geladen, wenn die Symbolleiste vorhanden ist

Meine XML für die Aktivität:

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="?attr/colorPrimary" 
    android:elevation="4dp" 
    android:paddingEnd="25dp"> 

    <EditText 
     android:id="@+id/searchBox" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:hint="Search or enter a URL" 
     android:imeOptions="actionDone" 
     android:inputType="textUri" 
     android:maxLines="1" /> 

</android.support.v7.widget.Toolbar> 

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

und das Java:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
toolbar.setTitleTextColor(ContextCompat.getColor(this, R.color.colorAccent)); 
setSupportActionBar(toolbar); 
getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
getSupportActionBar().setTitle(""); 

final WebView webView = (WebView) findViewById(R.id.webView); 
webView.loadUrl("https://www.google.com"); 
+0

was ist das übergeordnete Layout dieser beiden Ansichten? Kannst du ganze XML-Datei posten –

+0

In Ihrem Layout XML verwenden: Inside ' ' –

+0

eine mögliche Lösung, verpasst die Internet-Erlaubnis

Antwort

0

Ihre Layout-Struktur ändern, layout_below Tag in WebView hinzuzufügen. Ihre Layout-Struktur wie:

<android.support.v7.widget.Toolbar 
android:id="@+id/toolbar" 
android:layout_width="match_parent" 
android:layout_height="?attr/actionBarSize" 
android:background="?attr/colorPrimary" 
android:elevation="4dp" 
android:paddingEnd="25dp"> 

<EditText 
    android:id="@+id/searchBox" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:hint="Search or enter a URL" 
    android:imeOptions="actionDone" 
    android:inputType="textUri" 
    android:maxLines="1" /> 

</android.support.v7.widget.Toolbar> 

<WebView 
    android:id="@+id/webView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/toolbar" 
/> 

Auch webView.getSettings.setJavaScriptEnabled(true); im Actvity hinzuzufügen.

0

Facepalm, ich bin ein LinearLayout für mein Stammelement verwendet und hatte die Orientierung auf horizontal gesetzt ........

Verwandte Themen