есть LollipopFixedWebView, который не разбивает выпадающие и другие вещи - PullRequest
0 голосов
/ 28 января 2020

Это просто ответ на этот ответ . Но поскольку у меня еще нет 50 репутации, я не могу комментировать там.

Я сделал так, чтобы веб-просмотр работал нормально на всем, кроме Android Lollipop. Теперь мне нужно сделать то же самое на Android Lollipop. Мой LollipopFixedWebView выглядит следующим образом (это Kotlin код):

import android.annotation.TargetApi
import android.content.Context
import android.content.res.Configuration
import android.os.Build
import android.util.AttributeSet
import android.webkit.WebView

internal class LollipopFixedWebView : WebView {

    companion object {
        private fun getFixedContext(context: Context): Context {
            return if (Build.VERSION.SDK_INT !in Build.VERSION_CODES.LOLLIPOP..Build.VERSION_CODES.LOLLIPOP_MR1) {
                //on everything except Android Lollipop, there is nothing that needs to be fixed.
                // On these devices this class just works like a regular WebView.
                context
            } else {
                //FIXME this still breaks dropdowns in the webview
                /*
                calling createConfigurationContext seems to make the webview inflatable.
                something in that function has to be the cause.
                */
                context.createConfigurationContext(context.resources.configuration)
            }
        }
    }

    internal constructor(context: Context) : super(getFixedContext(context))

    internal constructor(context: Context, attrs: AttributeSet) : super(getFixedContext(context), attrs)

    internal constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(getFixedContext(context), attrs, defStyleAttr)

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    internal constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(getFixedContext(context), attrs, defStyleAttr, defStyleRes)

    internal constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, privateBrowsing: Boolean) : super(getFixedContext(context), attrs, defStyleAttr, privateBrowsing)
}

В результате моего тестирования вызов функции createConfigurationContext превращает контекст из одного из типов моего подкласса Activity в один из типов ContextImpl.

...