Java Code Examples for android.webkit.WebView#getLayoutParams()

The following examples show how to use android.webkit.WebView#getLayoutParams() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomizedProgressActivity.java    From android-oauth-client with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    Context context = inflater.getContext();
    DisplayMetrics metrics = context.getResources().getDisplayMetrics();
    final int DIALOG_HEIGHT =
            (int) Math.min(0.8f * metrics.heightPixels, 1024);

    View root = inflater.inflate(R.layout.custom_ui, container, false);

    WebView wv = (WebView) root.findViewById(android.R.id.primary);
    LayoutParams params = wv.getLayoutParams();
    params.height = DIALOG_HEIGHT;
    wv.setLayoutParams(params);
    View progressContainer = root.findViewById(android.R.id.progress);
    params = progressContainer.getLayoutParams();
    params.height = DIALOG_HEIGHT;
    progressContainer.setLayoutParams(params);

    return root;
}
 
Example 2
Source File: WebViewCache.java    From tysq-android with GNU General Public License v3.0 5 votes vote down vote up
public WebViewCache(Context context, String url, int size) {

        mWebViewList = new ArrayList<>(size);

        int width = ScreenAdapterUtils.getScreenWidth();
        int height = ScreenAdapterUtils.getAdHeight();

        for (int i = 0; i < DEFAULT_WEBVIEW_NUM; i++){
            WebView webView = new WebView(context);
            webView.loadUrl(url);

            ViewGroup.LayoutParams layoutParams = webView.getLayoutParams();

            if (layoutParams == null){
                layoutParams = new ViewGroup.LayoutParams(width, height);
            } else {
                layoutParams.width = width;
                layoutParams.height = height;
            }

            webView.setLayoutParams(layoutParams);
            webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);

            WebSettings settings = webView.getSettings();
            settings.setJavaScriptEnabled(true);
            webView.addJavascriptInterface(new TyJavaScriptInterface(context), "android");

            mWebViewList.add(webView);
        }
    }
 
Example 3
Source File: VenvyWebLayout.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
private void init(Context context) {
    mWebView = new WebView(context);
    ViewGroup.LayoutParams params = mWebView.getLayoutParams();
    if (params == null) {
        params = new ViewGroup.LayoutParams(-1, -1);
    }
    params.width = -1;
    params.height = -1;
    addView(mWebView, params);
}
 
Example 4
Source File: FlexibleSpaceToolbarWebViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_flexiblespacetoolbarwebview);

    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    ActionBar ab = getSupportActionBar();
    if (ab != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    mFlexibleSpaceView = findViewById(R.id.flexible_space);
    mTitleView = (TextView) findViewById(R.id.title);
    mTitleView.setText(getTitle());
    setTitle(null);
    mToolbarView = findViewById(R.id.toolbar);

    mWebViewContainer = findViewById(R.id.webViewContainer);

    final ObservableScrollView scrollView = (ObservableScrollView) findViewById(R.id.scroll);
    scrollView.setScrollViewCallbacks(this);

    WebView webView = (WebView) findViewById(R.id.webView);
    webView.loadUrl("file:///android_asset/lipsum.html");

    mFlexibleSpaceHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_height);
    int flexibleSpaceAndToolbarHeight = mFlexibleSpaceHeight + getActionBarSize();

    final FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) webView.getLayoutParams();
    layoutParams.topMargin = flexibleSpaceAndToolbarHeight;
    webView.setLayoutParams(layoutParams);

    mFlexibleSpaceView.getLayoutParams().height = flexibleSpaceAndToolbarHeight;

    ScrollUtils.addOnGlobalLayoutListener(mTitleView, new Runnable() {
        @Override
        public void run() {
            updateFlexibleSpaceText(scrollView.getCurrentScrollY());
        }
    });
}