Android XWalkView Layout problems

804 Views Asked by At

I was using XWalkView before in a Fragment with overlay Views in RL.

Now I wanted to use it in an Acitvity, but I get Layout rendering problems and Snackbar isn't working anymore.

enter image description here

XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".GenerateActivity"
    tools:showIn="@layout/activity_generate">

   <org.xwalk.core.XWalkView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>



   <!--<WebView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </WebView>-->


    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentTop="true"
        android:background="@drawable/btn_default"
        android:elevation="4dp"
        android:visibility="visible"
        android:id="@+id/ll_seat_mode_info"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:paddingBottom="5dp"
        android:paddingTop="5dp"
        android:layout_marginTop="16dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="With normal WebView"
            android:textColor="@color/colorAccent" />

    </LinearLayout>

</RelativeLayout>

The Layout is a Basic Acitvity, that means it's within a CoordinatorLayout.

XWalkView Initialization:

public class GenerateActivity extends AppCompatActivity {

    Snackbar snackbar;
    View snackView;
    XWalkView lWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_generate);

        // Toolbar
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        if(toolbar != null) {
            setSupportActionBar(toolbar);
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            toolbar.setNavigationOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onBackPressed();
                }
            });
        }

         initWebView();

         // Snackbar Code...

    }

    private void initWebView() {
        lWebView = (XWalkView) findViewById(R.id.webView);

        lWebView.clearCache(true);
        File lFile = new File("android_asset/index.html");

        XWalkPreferences.setValue("enable-javascript", true);
        XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, false);

        lWebView.load("file:///" + lFile.getAbsolutePath(), null);
    }

}

Dependency:

compile 'org.xwalk:xwalk_core_library:22.52.561.4'

Does somebody know's why and how to fix it?

Thank you!

// EDIT

I found a workaround. By adding 1dp padding below everything is fine... I tried XWalkView the same way in a new project and got the same problem. Maybe It's a problem of the library.

1

There are 1 best solutions below

3
On

You did not give the much more information about, how you are getting your XWalkView in activity but i am posting an example from that You can get some knowledge:

import android.app.Activity;
   import android.os.Bundle;

   import org.xwalk.core.XWalkResourceClient;
   import org.xwalk.core.XWalkUIClient;
   import org.xwalk.core.XWalkView;

   public class MyActivity extends Activity {
       XWalkView mXwalkView;

       class MyResourceClient extends XWalkResourceClient {
           MyResourceClient(XWalkView view) {
               super(view);
           }

           @Override
           WebResourceResponse shouldInterceptLoadRequest(XWalkView view, String url) {
               // Handle it here.
               ...
           }
       }

       class MyUIClient extends XWalkUIClient {
           MyUIClient(XWalkView view) {
               super(view);
           }

           @Override
           void onFullscreenToggled(XWalkView view, String url) {
               // Handle it here.
               ...
           }
       }

       @Override
       protected void onCreate(Bundle savedInstanceState) {
           mXwalkView = new XWalkView(this, null);
           setContentView(mXwalkView);
           mXwalkView.setResourceClient(new MyResourceClient(mXwalkView));
           mXwalkView.setUIClient(new MyUIClient(mXwalkView));
           mXwalkView.load("http://www.google.com", null);
       }

       @Override
       protected void onPause() {
           super.onPause();
           if (mXwalkView != null) {
               mXwalkView.pauseTimers();
               mXwalkView.onHide();
           }
       }

       @Override
       protected void onResume() {
           super.onResume();
           if (mXwalkView != null) {
               mXwalkView.resumeTimers();
               mXwalkView.onShow();
           }
       }

       @Override
       protected void onDestroy() {
           super.onDestroy();
           if (mXwalkView != null) {
               mXwalkView.onDestroy();
           }
       }

       @Override
       protected void onActivityResult(int requestCode, int resultCode, Intent data) {
           if (mXwalkView != null) {
               mXwalkView.onActivityResult(requestCode, resultCode, data);
           }
       }

       @Override
       protected void onNewIntent(Intent intent) {
           if (mXwalkView != null) {
               mXwalkView.onNewIntent(intent);
           }
       }
   }

In gradle file you have to add dependencies like:

compile 'org.xwalk:xwalk_core_library:10.39.235.15'