Как открыть новые вкладки в приложении браузера WebView - PullRequest
0 голосов
/ 16 апреля 2020

Итак, я пытался создать приложение для браузера в студии android, но я не могу найти способ кодирования для открытия новых вкладок (например, chrome).

Чтобы разрешить Вы знаете, над чем я работаю, вот некоторые фотографии activity_main. xml*

, когда нажимается кнопка, открывается другой макет, содержащий представление сетки, для которого должны быть запущены все в данный момент. вкладки в нем.

Вот пи c для вкладок. tab_layout. xml.

В этом макете при нажатии кнопки '+' новая вкладка должен быть создан, и старая вкладка должна быть доступна через сетку.

activity_main. xml: `` `

<?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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context=".MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <include
            android:id="@+id/toolbar"
            layout="@layout/searchBar" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="1.3dp"
            android:background="@color/mainWhite">

            <ProgressBar
                android:id="@+id/progress"
                style="@style/Widget.AppCompat.ProgressBar.Horizontal"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/mainWhite"
                android:max="100"
                android:progressBackgroundTint="@color/mainWhite" />
        </LinearLayout>
    </com.google.android.material.appbar.AppBarLayout>

    <LinearLayout
        android:id="@+id/webVLay"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:addStatesFromChildren="true"
        android:fitsSystemWindows="true"
        android:orientation="vertical"
        android:visibility="visible">


        <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
            android:id="@+id/refresh"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <WebView
                android:id="@+id/webview"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:scrollbarSize="1.5dp"
                android:scrollbarStyle="insideOverlay"
                android:scrollbarThumbHorizontal="@drawable/scrollbar"
                android:scrollbarThumbVertical="@drawable/scrollbar"
                android:scrollbars="vertical|horizontal"
                tools:targetApi="m" />
        </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/errorPage"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:fitsSystemWindows="true"
        android:orientation="vertical"
        android:visibility="gone">

        <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
            android:id="@+id/errorRefresh"
            android:layout_width="match_parent"
            android:layout_height="fill_parent">


            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:contentDescription="@null"
                    android:scaleType="centerCrop"
                    android:src="@drawable/bg" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@android:color/transparent"
                    android:orientation="horizontal">

                    <ImageView
                        android:layout_width="100dp"
                        android:layout_height="100dp"
                        android:layout_margin="35dp"
                        android:contentDescription="@null"
                        android:src="@drawable/ic_default_web" />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:fontFamily="sans-serif-condensed"
                        android:gravity="top"
                        android:paddingTop="60dp"
                        android:text="@string/cannot_load_page"
                        android:textColor="@color/Black"
                        android:textSize="25sp" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="20dp"
                    android:orientation="horizontal"
                    android:padding="35dp">

                    <TextView
                        android:id="@+id/error_msg"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />
                </LinearLayout>
            </FrameLayout>
        </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1px"
        android:background="@android:color/darker_gray" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">

        <include layout="@layout/d_actionbar" />
    </LinearLayout>
</LinearLayout>     ```

tab_layout. xml:` ``

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:elevation="10dp"
    android:background="@color/mainWhite"
    android:orientation="horizontal">

    <ImageButton
        android:id="@+id/back"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:contentDescription="@null"
        android:padding="15dp"
        android:src="@drawable/ic_arrow_back" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:fontFamily="sans-serif-smallcaps"
        android:gravity="center_vertical"
        android:text="@string/tabs"
        android:textColor="@color/Black"
        android:textSize="25sp" />

    <Button
        android:id="@+id/addTab"
        android:layout_width="20dp"
        android:layout_height="30dp"
        android:layout_gravity="center"
        android:background="@drawable/tab_bg"
        android:text="@string/add" />

    <ImageButton
        android:id="@+id/settings"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:contentDescription="@null"
        android:padding="15dp"
        android:src="@drawable/ic_settings" />
</LinearLayout>

<GridLayout
    android:id="@+id/tabView"
    android:fitsSystemWindows="true"
    android:layout_width="match_parent"
    android:layout_height="fill_parent" />

`` `

Я новичок в кодировании и android studio.

Можно ли это сделать? если да, то как? Заранее спасибо ..

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...