не удается увидеть текстовое поле во время эмуляции или живого тестирования в Android studio

#android #xml #android-studio #kotlin

Вопрос:

Я создаю веб-браузер с javascript и html, но у меня возникла эта проблема. Это макет моего приложения:

введите описание изображения здесь

но когда я подражаю этому:

введите описание изображения здесь

текстовое поле исчезло.
Версия эмулятора для Android-9.0 pie.
Я включил это приложение для работы на Android 4.1 и новее.

Это мое activity_main.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:id="@ id/pa"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="10dp"
    android:padding="0dp"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="bottom"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="parent">

        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="0dp"
            app:cardCornerRadius="20dp">

            <com.google.android.material.textfield.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@ id/webtext"
                    android:layout_width="278dp"
                    android:layout_height="match_parent"
                    android:gravity="top"
                    android:hint="hint"/>
            </com.google.android.material.textfield.TextInputLayout>

            <Button
                android:id="@ id/butt"
                android:layout_width="wrap_content"
                android:layout_height="61dp"
                android:layout_gravity="right"
                android:text="go to web" />

            <WebView
                android:id="@ id/web"
                android:layout_width="match_parent"
                android:layout_height="650dp"
                android:layout_alignParentBottom="true"
                android:layout_gravity="bottom" />
        </androidx.cardview.widget.CardView>
    </LinearLayout>
</RelativeLayout>
 

and this is the mainfest.xml file:

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.kaharigoweb10">

    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher_foreground"
        android:label="@string/app_name"
        android:roundIcon="@drawable/ic_launcher_background"
        android:supportsRtl="true"
        android:theme="@style/Theme.KahariGoWeb10">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

 

Это файл kt:

 package com.example.kaharigoweb10

import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.webkit.WebView
import android.webkit.WebViewClient
import android.widget.Button
import android.widget.EditText

class MainActivity : AppCompatActivity() {

    @SuppressLint("SetJavaScriptEnabled")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val web: WebView = findViewById(R.id.web)
        val webtext: EditText = findViewById(R.id.webtext)
        val button: Button = findViewById(R.id.butt)
        button.setOnClickListener{
            val string = webtext.text.toString()
            web.settings.javaScriptEnabled = true
            web.webViewClient = WebViewClient()
            web.loadUrl(string)
        }
    }
}
 

Я хочу, чтобы javascript и webtext были переменной, в которой хранится текст, набранный исчезнувшим текстовым полем.
Кроме того, в веб-представлении не отображались большие веб-сайты, такие как www.google.com и это тоже проблема.
Я получаю сообщение об ошибке в форме logcat:

 2019-05-19 03:47:06.132 414-414/? E/MFI-Conn:  (          mdfx_conn_conn,   76) mdfx_conn_conn(): the MFI connection fails!!
2019-05-19 03:47:06.132 414-414/? E/MFI-Conn:  (   mdfx_conn_init_legacy,  363) mdfx_conn_init_legacy(): mdfx_conn_conn() error!
 

То, что я пытался, — это просмотреть все статьи, но я не могу найти ту, которую хочу.
Я использую Windows 10 и Android studio 4.1.

Ответ №1:

попробуйте переместить положение webview в xml на тот же уровень, что и CardView:

 <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:id="@ id/pa"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="10dp"
    android:padding="0dp"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="bottom"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="parent">

        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="0dp"
            app:cardCornerRadius="20dp">

            <com.google.android.material.textfield.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@ id/webtext"
                    android:layout_width="278dp"
                    android:layout_height="match_parent"
                    android:gravity="top"
                    android:hint="hint"
                    />

            </com.google.android.material.textfield.TextInputLayout>

            <Button
                android:id="@ id/butt"
                android:layout_width="wrap_content"
                android:layout_height="61dp"
                android:layout_gravity="right"
                android:text="go to web" />

        </androidx.cardview.widget.CardView>

        <WebView
            android:id="@ id/web"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentBottom="true"
            android:layout_gravity="bottom" />
    </LinearLayout>
</RelativeLayout>