Как скрыть и показать компонент Android одним нажатием на экран в Webview? - PullRequest
0 голосов
/ 06 мая 2020

В моем проекте Android я разработал один . xml макет , где я использовал один Webview . И внутри этого webView я добавил некоторые другие android компоненты, такие как - Linearlayout, Buttons, SeekBar, TextView .

Вот код для моего. xml макет-

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="@+id/relativeWebview"
    tools:context=".new_package.reader_version_2.reader_v2.ReaderV2Activity">

    <WebView
        android:id="@+id/activity_checkout_webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="0dp"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:visibility="gone"
        >

        <ProgressBar
            android:id="@+id/progressBar"
            style="?android:attr/progressBarStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_x="168dp"
            android:layout_y="223dp"
            android:visibility="gone"
            />
    </WebView>


    <WebView
        android:id="@+id/web_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="none"
        android:paddingBottom="60dp"
        />


    <LinearLayout
        android:id="@+id/linearSeekBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true"
        android:background="#ffffff"
        >


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            >

            <SeekBar
                android:id="@+id/seekBar1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginTop="5dp"
                android:max="100"
                android:progressTint="#cdcdcd"
                android:thumbTint="#000000"
                />


            <TextView
                android:id="@+id/tvProgress"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="2dp"
                android:text="Brightness"
                android:textAlignment="center"
                android:textStyle="bold"
                android:textAppearance="?android:attr/textAppearanceLarge" />


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                >

                <Button
                    android:id="@+id/btnBackground"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="background"

                    />

                <Button
                    android:id="@+id/btnFontSize"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="font"

                    />

                <Button
                    android:id="@+id/btnSave"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="save"
                    />

            </LinearLayout>

        </LinearLayout>

    </LinearLayout>

</RelativeLayout>

Вот результат этого макета -

enter image description here

***** * Итак, теперь проблема в *******

Я хочу, чтобы LinearLayout (внизу экрана) скрывался одним нажатием на экране, и его также не будет видно, пока я прокручиваю экран. Он появится снова, когда я снова сделаю одно касание на экране.

Короче говоря, мне нужно решение для этого, чтобы я мог скрыть и показать этот макет внутри веб-просмотра одним нажатием.

Я пробовал следующие решения, но ни одно из них не сработало для меня - Как скрыть и показать кнопки при альтернативных событиях касания

Ответы [ 2 ]

0 голосов
/ 07 мая 2020

Привет, попробуйте этот код, как показано ниже, чтобы скрыть строку состояния и компонент, это поможет вам скрыть строку состояния и компонент

 public void setStatusbarTransparent(Activity activity) {
        Window window = activity.getWindow();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(0x00000000);


            // transparent
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            int flags = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
            window.addFlags(flags);
        }
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);

    }
0 голосов
/ 06 мая 2020

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

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    try {
        return super.onInterceptTouchEvent(ev);
    } catch (IllegalArgumentException | IndexOutOfBoundsException ex) {
        // Do nothing.
    }
    return false;
}

Если MotionEvent находится в представлении, на которое вы нацеливаетесь, вы можете применить свой logi c.

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