Панель инструментов Android и Webview - PullRequest
0 голосов
/ 12 ноября 2018

У меня есть веб-просмотр и панель инструментов. Без панели инструментов веб-представление полностью прокручивается, но когда я добавляю панель инструментов, веб-представление больше не прокручивается. Я пробовал NestedScrollView, но он просто не работает. Вот схема моей деятельности:

<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal"
                android:weightSum="100">
                <ImageButton
                    android:id="@+id/homeButton"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="20"
                    android:contentDescription="@string/home"
                    app:srcCompat="@drawable/ic_home" />
                <TextView
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="60"
                    android:gravity="center"
                    android:text="@string/app_name"
                    android:textSize="24sp"
                    android:textStyle="bold"
                    app:fontFamily="Sans Serif" />
                <ImageButton
                    android:id="@+id/menuButton"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="20"
                    android:contentDescription="@string/menu"
                    app:srcCompat="@drawable/ic_menu_black_24dp" />
            </LinearLayout>
        </android.support.v7.widget.Toolbar>

        <RelativeLayout
            android:id="@+id/relative"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context=".MailActivity">
            <WebView
                android:id="@+id/webview"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
        </RelativeLayout>
    </android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>

Java-код для панели инструментов просто создает меню и домашнюю кнопку, в то время как веб-просмотр просто загружает URL (javascript включен). Большое спасибо за вашу помощь!

Ответы [ 3 ]

0 голосов
/ 12 ноября 2018
<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal"
                android:weightSum="100">
                <ImageButton
                    android:id="@+id/homeButton"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="20"
                    android:contentDescription="@string/home"
                    app:srcCompat="@drawable/ic_home" />
                <TextView
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="60"
                    android:gravity="center"
                    android:text="@string/app_name"
                    android:textSize="24sp"
                    android:textStyle="bold"
                    app:fontFamily="Sans Serif" />
                <ImageButton
                    android:id="@+id/menuButton"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="20"
                    android:contentDescription="@string/menu"
                    app:srcCompat="@drawable/ic_menu_black_24dp" />
            </LinearLayout>
        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

             <WebView
                android:id="@+id/webview"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</android.support.design.widget.CoordinatorLayout>
0 голосов
/ 12 ноября 2018
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

      <android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:weightSum="100">
            <ImageButton
                android:id="@+id/homeButton"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="20"
                android:contentDescription="@string/home"
                app:srcCompat="@drawable/ic_home" />
            <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="60"
                android:gravity="center"
                android:text="@string/app_name"
                android:textSize="24sp"
                android:textStyle="bold"
                app:fontFamily="Sans Serif" />
            <ImageButton
                android:id="@+id/menuButton"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="20"
                android:contentDescription="@string/menu"
                app:srcCompat="@drawable/ic_menu_black_24dp" />
        </LinearLayout>
    </android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>

      <WebView
    android:id="@+id/webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</LinearLayout>
0 голосов
/ 12 ноября 2018

Вы должны переместить Относительный макет за пределы панели приложения.

...