android crosswalk-webview 取代 webview

在官网下载crosswalk-webview

https://crosswalk-project.org/documentation/downloads.html

参照https://crosswalk-project.org/documentation/embedding_crosswalk.html 中的方法在项目中添加


使用方法:

在布局文件中使用




在Activity.java文件中

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


public class MainActivity extends Activity{
	
	private XWalkView mXwalkView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_main);
		
		mXwalkView = (XWalkView)findViewById(R.id.walkview);
		

                mXwalkView.load("http://www.baidu.com", null);
        
                mXwalkView.setResourceClient(new XWalkResourceClient(mXwalkView){	
        	     @Override	
        	     public void onLoadFinished(XWalkView view, String url) {		
        		super.onLoadFinished(view, url);	
        	     }	

        	     @Override	
        	     public void onLoadStarted(XWalkView view, String url) {		
        		super.onLoadStarted(view, url);	
        	     }
                });
	}
	
    @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);
        }
    }
}




你可能感兴趣的:(android)