通过@JavascriptInterface更改视图的可见性

时间:2019-02-03 16:20:13

标签: android android-layout android-view

由于WebView中的javascript函数,我试图使标签布局导航变得可见。我已经成功设置了简单的吐司消息,但似乎无法与活动中的任何视图进行交互。

我的java @JavascriptInterface方法如下:

 @JavascriptInterface
    public void anchorMode(String toggle){
        Toast toasty=Toast.makeText(context,toggle,Toast.LENGTH_LONG);
        toasty.show();
        runOnUiThread(new Runnable(){

            public void run(){
                tabLayout=findViewById(R.id.TabLayouts);
                tabLayout.setVisibility(View.VISIBLE);
            }

        });

    }

我已经添加了runOnUiThread函数,因为我看到这可能是解决该问题的一种方法,但是唯一改变的是,现在,anchorMode()函数执行后,应用程序便崩溃了。 另外,在tabLayout上下文之外,我也可以与@JavascriptInterface视图进行交互。

0 个答案:

没有答案