启用YouTube视频从全屏返回后,Android软键盘将不显示

rlcwz9us  于 2023-05-15  发布在  Android
关注(0)|答案(2)|浏览(121)

我的应用程序大量使用youtube视频来回答有关产品和这些产品安装的问题。只是为了上下文,我是一个全栈Web开发人员,只有一个月的java/android studio开发经验。该应用程序仅用JavaScript和CSS编写,我使用Android WebView将其显示为应用程序。目前,我有一个web chrome客户端,它隐藏了完整的youtube视频,也显示了全屏的youtube视频。一旦一个视频是全屏,然后回到正常视图,如果我点击一个输入字段的键盘不显示,我得到的消息在调试器。
“I/AssistStructure:展平的最终辅助数据:1928字节,包含1个窗口,5个视图”
认为这是从网页浏览器客户端隐藏自定义视图。
认为答案是检查视图是否是键盘,而不是执行onHideCustomView();但我不确定是不是这样,或者我只是在做一些愚蠢的事情。
下面是大多数应用程序的代码或足够的上下文。
谢谢你们花时间帮我。
此外,任何指针,如果我可以改善这一进程将不胜感激。
Thank You:)

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getSupportActionBar().hide();
    myWebView = new WebView(this);
    setContentView(myWebView);
    myWebView.setWebChromeClient(new MyChrome());
    myWebView.setWebViewClient(new WebViewClient());
    myWebView.loadUrl("url");

    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    myWebView.requestFocus(View.FOCUS_DOWN);

}

@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public boolean onKeyDown (int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        String webUrl = myWebView.getUrl();
        if (webUrl.indexOf("directory/url") < 0){

                myWebView.loadUrl("url");

            return true;
        }else {
            myWebView.loadUrl("javascript:android();");
            return true;
        }

    }
    return super.onKeyDown(keyCode, event);

}

private class MyChrome extends WebChromeClient {

    private View mCustomView;
    private WebChromeClient.CustomViewCallback mCustomViewCallback;
    protected FrameLayout mFullscreenContainer;
    private int mOriginalOrientation;
    private int mOriginalSystemUiVisibility;

    MyChrome() {}


    public void onHideCustomView()
    {
        ((FrameLayout)getWindow().getDecorView()).removeView(this.mCustomView);
        this.mCustomView = null;
        getWindow().getDecorView().setSystemUiVisibility(this.mOriginalSystemUiVisibility);
        setRequestedOrientation(this.mOriginalOrientation);
        this.mCustomViewCallback.onCustomViewHidden();
        this.mCustomViewCallback = null;
    }

    public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback paramCustomViewCallback)
    {
        if (this.mCustomView != null)
        {
            onHideCustomView();
            return;
        }
        this.mCustomView = paramView;
        this.mOriginalSystemUiVisibility = getWindow().getDecorView().getSystemUiVisibility();
        this.mOriginalOrientation = getRequestedOrientation();
        this.mCustomViewCallback = paramCustomViewCallback;
        ((FrameLayout)getWindow().getDecorView()).addView(this.mCustomView, new FrameLayout.LayoutParams(-1, -1));
        getWindow().getDecorView().setSystemUiVisibility(3846);
    }
}
2hh7jdfx

2hh7jdfx1#

只是必须清除web视图上的焦点

public void onHideCustomView()
{
    ((FrameLayout)getWindow().getDecorView()).removeView(this.mCustomView);
    this.mCustomView = null;
    getWindow().getDecorView().setSystemUiVisibility(this.mOriginalSystemUiVisibility);
    setRequestedOrientation(this.mOriginalOrientation);
    this.mCustomViewCallback.onCustomViewHidden();
    this.mCustomViewCallback = null;
    myWebView.clearFocus();
}
ccgok5k5

ccgok5k52#

只要清除webview的焦点就可以了。

public void onHideCustomView()
    {

        ((FrameLayout)MainUI.this.getWindow().getDecorView()).removeView(this.mCustomView);
        this.mCustomView = null;
        MainUI.this.getWindow().getDecorView()
                .setSystemUiVisibility(this.mOriginalSystemUiVisibility);
        MainUI.this.setRequestedOrientation(this.mOriginalOrientation);
        this.mCustomViewCallback.onCustomViewHidden();
        this.mCustomViewCallback = null;

        ((FrameLayout)getWindow().getDecorView()).removeView(this.mCustomView);
        webView.clearFocus();
  }

相关问题