android.webkit.WebView#setLayoutParams ( )源码实例Demo

下面列出了android.webkit.WebView#setLayoutParams ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: WhereYouGo   文件: AboutDialog.java
@Override
public Dialog createDialog(Bundle savedInstanceState) {
    String buffer = "<div align=\"center\"><h2><b>" + A.getAppName() + "</b></h2></div>" +
            "<div align=\"center\"><h3><b>" + A.getAppVersion() + "</b></h3></div>" +
            CustomMainActivity.loadAssetString(PreferenceValues.getLanguageCode() + "_first.html") +
            "<br /><br />" +
            CustomMainActivity.loadAssetString(PreferenceValues.getLanguageCode() + "_about.html") +
            "<br /><br />" +
            VersionInfo.getNews(1, PreferenceValues.getApplicationVersionActual());
    // add info
    // add about info
    // add news

    WebView webView = new WebView(A.getMain());
    webView.loadData(buffer, "text/html; charset=utf-8", "utf-8");
    webView.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT));
    webView.setBackgroundColor(Color.WHITE);

    return new AlertDialog.Builder(getActivity()).setTitle(R.string.about_application)
            .setIcon(R.drawable.ic_title_logo).setView(webView).setNeutralButton(R.string.close, null)
            .create();
}
 
源代码2 项目: WhereYouGo   文件: UtilsGUI.java
public static WebView getFilledWebView(Activity activity, String data) {
    WebView webView = new WebView(activity);
    // webView.loadData(UtilsHttp.repairHtmlFile(data), "text/html", "utf-8");
    try {
        // webView.loadData(URLEncoder.encode(
        // UtilsHttp.repairHtmlFile(data),"utf-8").replaceAll("\\+"," "),
        // "text/html", "utf-8");
        // http://stackoverflow.com/questions/4917860/android-character-encoding-raw-resource-files
        webView.loadDataWithBaseURL(null, data.replaceAll("\\+", " "), "text/html", "utf-8", null);
    } catch (Exception e) {
    }
    webView
            .setLayoutParams(new ViewGroup.LayoutParams(getDialogWidth(), LayoutParams.WRAP_CONTENT));
    webView.setBackgroundColor(Color.WHITE);
    return webView;
}
 
源代码3 项目: facebooklogin   文件: WebDialog.java
@SuppressLint("SetJavaScriptEnabled")
private void setUpWebView(int margin) {
    LinearLayout webViewContainer = new LinearLayout(getContext());
    webView = new WebView(getContext());
    webView.setVerticalScrollBarEnabled(false);
    webView.setHorizontalScrollBarEnabled(false);
    webView.setWebViewClient(new DialogWebViewClient());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl(url);
    webView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                                         ViewGroup.LayoutParams.MATCH_PARENT));
    webView.setVisibility(View.INVISIBLE);
    webView.getSettings().setSavePassword(false);

    webViewContainer.setPadding(margin, margin, margin, margin);
    webViewContainer.addView(webView);
    contentFrameLayout.addView(webViewContainer);
}
 
源代码4 项目: ucar-weex-core   文件: WXWebView.java
@Override
public View getView() {
    FrameLayout root = new FrameLayout(mContext);
    root.setBackgroundColor(Color.WHITE);

    mWebView = new WebView(mContext);//mContext.getApplicationContext();
    FrameLayout.LayoutParams wvLayoutParams =
            new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
                    FrameLayout.LayoutParams.MATCH_PARENT);
    wvLayoutParams.gravity = Gravity.CENTER;
    mWebView.setLayoutParams(wvLayoutParams);
    root.addView(mWebView);
    initWebView(mWebView);

    mProgressBar = new ProgressBar(mContext);
    showProgressBar(false);
    FrameLayout.LayoutParams pLayoutParams =
            new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
                    FrameLayout.LayoutParams.WRAP_CONTENT);
    mProgressBar.setLayoutParams(pLayoutParams);
    pLayoutParams.gravity = Gravity.CENTER;
    root.addView(mProgressBar);
    return root;
}
 
源代码5 项目: cloudflare-scrape-Android   文件: WebViewDialog.java
private void initWebView(){
    mWebView = new WebView(mContext);
    ConstraintLayout.LayoutParams layoutParams =
            new ConstraintLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT);
    layoutParams.startToStart = ConstraintLayout.LayoutParams.PARENT_ID;
    layoutParams.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID;
    layoutParams.topToTop = ConstraintLayout.LayoutParams.PARENT_ID;
    layoutParams.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID;
    mWebView.setLayoutParams(layoutParams);
    mWebView.setId(R.id.webview);
    mWebView.setVisibility(View.INVISIBLE);
    mLayout.addView(mWebView,-1);
    mAdvanceWebClient = new AdvanceWebClient(getContext(), mWebView,mUser_agent);
    mAdvanceWebClient.setListener(mLoginSuccessListener);
    mAdvanceWebClient.initWebView("https://" + mUrl.getHost());
}
 
源代码6 项目: AndroidInstagram   文件: InstagramDialog.java
private void setUpWebView() {
	mWebView = new WebView(getContext());
        
	mWebView.setVerticalScrollBarEnabled(false);
	mWebView.setHorizontalScrollBarEnabled(false);
	mWebView.setWebViewClient(new InstagramWebViewClient());
	mWebView.getSettings().setJavaScriptEnabled(true);
	mWebView.loadUrl(mAuthUrl);
	mWebView.setLayoutParams(FILL);
        
	WebSettings webSettings = mWebView.getSettings();
	
	webSettings.setSavePassword(false);
	webSettings.setSaveFormData(false);
	
	mContent.addView(mWebView);
}
 
源代码7 项目: Klyph   文件: WebDialog.java
@SuppressLint("SetJavaScriptEnabled")
private void setUpWebView(int margin) {
    LinearLayout webViewContainer = new LinearLayout(getContext());
    webView = new WebView(getContext());
    webView.setVerticalScrollBarEnabled(false);
    webView.setHorizontalScrollBarEnabled(false);
    webView.setWebViewClient(new DialogWebViewClient());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl(url);
    webView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    webView.setVisibility(View.INVISIBLE);
    webView.getSettings().setSavePassword(false);

    webViewContainer.setPadding(margin, margin, margin, margin);
    webViewContainer.addView(webView);
    webViewContainer.setBackgroundColor(BACKGROUND_GRAY);
    contentFrameLayout.addView(webViewContainer);
}
 
源代码8 项目: weex-uikit   文件: WXWebView.java
@Override
public View getView() {
    FrameLayout root = new FrameLayout(mContext);
    root.setBackgroundColor(Color.WHITE);

    mWebView = new WebView(mContext);//mContext.getApplicationContext();
    FrameLayout.LayoutParams wvLayoutParams =
            new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
                    FrameLayout.LayoutParams.MATCH_PARENT);
    wvLayoutParams.gravity = Gravity.CENTER;
    mWebView.setLayoutParams(wvLayoutParams);
    root.addView(mWebView);
    initWebView(mWebView);

    mProgressBar = new ProgressBar(mContext);
    showProgressBar(false);
    FrameLayout.LayoutParams pLayoutParams =
            new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
                    FrameLayout.LayoutParams.WRAP_CONTENT);
    mProgressBar.setLayoutParams(pLayoutParams);
    pLayoutParams.gravity = Gravity.CENTER;
    root.addView(mProgressBar);
    return root;
}
 
源代码9 项目: drupalfit   文件: WebDialog.java
@SuppressLint("SetJavaScriptEnabled")
private void setUpWebView(int margin) {
    Log8.d();
    LinearLayout webViewContainer = new LinearLayout(getContext());
    webView = new WebView(getContext());
    webView.setVerticalScrollBarEnabled(false);
    webView.setHorizontalScrollBarEnabled(false);
    webView.setWebViewClient(new DialogWebViewClient());
    //webView.setWebChromeClient(new WebChromeClient());

    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl(url);
    webView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    webView.setVisibility(View.INVISIBLE);
    webView.getSettings().setSavePassword(false);
    webView.getSettings().setSaveFormData(false);

    webViewContainer.setPadding(margin, margin, margin, margin);
    webViewContainer.addView(webView);
    webViewContainer.setBackgroundColor(0xCC000000);
    contentFrameLayout.addView(webViewContainer);
    Log8.d();
}
 
源代码10 项目: FacebookImageShareIntent   文件: WebDialog.java
@SuppressLint("SetJavaScriptEnabled")
private void setUpWebView(int margin) {
    LinearLayout webViewContainer = new LinearLayout(getContext());
    webView = new WebView(getContext());
    webView.setVerticalScrollBarEnabled(false);
    webView.setHorizontalScrollBarEnabled(false);
    webView.setWebViewClient(new DialogWebViewClient());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl(url);
    webView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    webView.setVisibility(View.INVISIBLE);
    webView.getSettings().setSavePassword(false);
    webView.getSettings().setSaveFormData(false);

    webViewContainer.setPadding(margin, margin, margin, margin);
    webViewContainer.addView(webView);
    webViewContainer.setBackgroundColor(BACKGROUND_GRAY);
    contentFrameLayout.addView(webViewContainer);
}
 
源代码11 项目: android-skeleton-project   文件: WebDialog.java
@SuppressLint("SetJavaScriptEnabled")
private void setUpWebView(int margin) {
    LinearLayout webViewContainer = new LinearLayout(getContext());
    webView = new WebView(getContext());
    webView.setVerticalScrollBarEnabled(false);
    webView.setHorizontalScrollBarEnabled(false);
    webView.setWebViewClient(new DialogWebViewClient());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl(url);
    webView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    webView.setVisibility(View.INVISIBLE);
    webView.getSettings().setSavePassword(false);
    webView.getSettings().setSaveFormData(false);

    webViewContainer.setPadding(margin, margin, margin, margin);
    webViewContainer.addView(webView);
    webViewContainer.setBackgroundColor(BACKGROUND_GRAY);
    contentFrameLayout.addView(webViewContainer);
}
 
源代码12 项目: Intra   文件: ServerApprovalDialogFragment.java
private View makeWebView(int index) {
  final String url = getResources().getStringArray(R.array.server_websites)[index];

  final WebView webView = new WebView(getContext());
  webView.getSettings().setJavaScriptEnabled(true);
  webView.setWebViewClient(new WebViewClient());  // Makes navigation stay in this webview.
  webView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
  webView.loadUrl(url);

  return webView;
}
 
源代码13 项目: 4pdaClient-plus   文件: EmoticsQuickView.java
@Override
View createView() {
    if (getContext() == null)
        return new View(getContext());
    LayoutInflater inflater = LayoutInflater.from(getContext());
    webView = new WebView(inflater.getContext());
    webView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    webView.setBackgroundColor(AppTheme.getThemeStyleWebViewBackground());
    loadWebView();
    return webView;
}
 
源代码14 项目: MiBandDecompiled   文件: TDialog.java
private void c()
{
    l = new ProgressBar((Context)c.get());
    android.widget.FrameLayout.LayoutParams layoutparams = new android.widget.FrameLayout.LayoutParams(-2, -2);
    layoutparams.gravity = 17;
    l.setLayoutParams(layoutparams);
    (new TextView((Context)c.get())).setText("test");
    k = new FrameLayout((Context)c.get());
    android.widget.FrameLayout.LayoutParams layoutparams1 = new android.widget.FrameLayout.LayoutParams(-1, -2);
    layoutparams1.bottomMargin = 40;
    layoutparams1.leftMargin = 80;
    layoutparams1.rightMargin = 80;
    layoutparams1.topMargin = 40;
    layoutparams1.gravity = 17;
    k.setLayoutParams(layoutparams1);
    k.setBackgroundResource(0x1080000);
    k.addView(l);
    android.widget.FrameLayout.LayoutParams layoutparams2 = new android.widget.FrameLayout.LayoutParams(-1, -1);
    j = new WebView((Context)c.get());
    j.setLayoutParams(layoutparams2);
    i = new FrameLayout((Context)c.get());
    layoutparams2.gravity = 17;
    i.setLayoutParams(layoutparams2);
    i.addView(j);
    i.addView(k);
    d = new WeakReference(k);
    setContentView(i);
}
 
源代码15 项目: 4pdaClient-plus   文件: BbCodesQuickView.java
@Override
View createView() {
    LayoutInflater inflater = LayoutInflater.from(getContext());
    webView = new WebView(inflater.getContext());
    webView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    webView.setBackgroundColor(AppTheme.getThemeStyleWebViewBackground());
    loadWebView();
    return webView;
}
 
源代码16 项目: MiBandDecompiled   文件: PKDialog.java
private void c()
{
    m = new a((Context)o.get());
    m.setBackgroundColor(0x66000000);
    m.setLayoutParams(new android.widget.RelativeLayout.LayoutParams(-1, -1));
    n = new WebView((Context)o.get());
    n.setBackgroundColor(0);
    n.setBackgroundDrawable(null);
    android.widget.RelativeLayout.LayoutParams layoutparams;
    if (android.os.Build.VERSION.SDK_INT >= 11)
    {
        try
        {
            Class aclass[] = new Class[2];
            aclass[0] = Integer.TYPE;
            aclass[1] = android/graphics/Paint;
            Method method = android/view/View.getMethod("setLayerType", aclass);
            WebView webview = n;
            Object aobj[] = new Object[2];
            aobj[0] = Integer.valueOf(1);
            aobj[1] = new Paint();
            method.invoke(webview, aobj);
        }
        catch (Exception exception)
        {
            exception.printStackTrace();
        }
    }
    layoutparams = new android.widget.RelativeLayout.LayoutParams(-1, p);
    layoutparams.addRule(13, -1);
    n.setLayoutParams(layoutparams);
    m.addView(n);
    m.a(this);
    setContentView(m);
}
 
源代码17 项目: freemp   文件: ActFreemporg.java
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //устанавливаем кастомный бэкграунд акшенбара
    getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar_bgr));
    //добавляем кнопку назад
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    activity = this;
    aq = new AQuery(activity);

    Bundle extras = getIntent().getExtras();
    if (extras == null) {
        return;
    } else {
        q = extras.getString("q");

    }
    //UI
    final LinearLayout linearLayout = new LinearLayout(activity);
    linearLayout.setOrientation(LinearLayout.VERTICAL);

    //Progress
    progressBar = new ProgressBar(activity, null, android.R.attr.progressBarStyleHorizontal);
    ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    progressBar.setLayoutParams(layoutParams);
    progressBar.setVisibility(View.GONE);
    webView = new WebView(activity);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new WebViewClient() {
                                 @Override
                                 public boolean shouldOverrideUrlLoading(WebView view, String url) {
                                     if (Uri.parse(url).getHost().contains("freemp.org")) {
                                         // This is my web site, so do not override; let my WebView load the page
                                         return false;
                                     }
                                     // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
                                     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                                     startActivity(intent);
                                     return true;
                                 }
                             }
    );
    ViewGroup.LayoutParams layoutParams2 = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    webView.setLayoutParams(layoutParams2);
    linearLayout.addView(progressBar);
    linearLayout.addView(webView);
    setContentView(linearLayout);
}
 
源代码18 项目: ClassSchedule   文件: Html5Activity.java
@SuppressLint("JavascriptInterface")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web);

    mSmoothProgress = findViewById(R.id.smooth_progress);

    Bundle bundle = getIntent().getBundleExtra("bundle");
    mUrl = bundle.getString("url");
    mTitle = bundle.getString("title", "");
    mJavaScriptInterface = bundle.getSerializable("javascript");

    initBackToolbar(TextUtils.isEmpty(mTitle) ? "加载中" : mTitle);

    Log.d("Url:", mUrl);
    Log.d("mTitle:", mTitle);


    mLayout = (LinearLayout) findViewById(R.id.web_layout);


    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    mWebView = new WebView(getApplicationContext());
    mWebView.setLayoutParams(params);
    mLayout.addView(mWebView);

    WebSettings mWebSettings = mWebView.getSettings();
    mWebSettings.setSupportZoom(true);
    mWebSettings.setLoadWithOverviewMode(true);
    mWebSettings.setUseWideViewPort(true);
    mWebSettings.setDefaultTextEncodingName("utf-8");
    mWebSettings.setLoadsImagesAutomatically(true);

    //调用JS方法.安卓版本大于17,加上注解 @JavascriptInterface
    mWebSettings.setJavaScriptEnabled(true);

    if (mJavaScriptInterface != null) {
        mWebView.addJavascriptInterface(mJavaScriptInterface, "android");
    }

    mWebView.setDownloadListener(new DownloadListener() {
        @Override
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
            downloadByBrowser(url);
        }
    });

    saveData(mWebSettings);

    newWin(mWebSettings);

    mWebView.setWebChromeClient(webChromeClient);


    mWebView.setWebViewClient(webViewClient);
    mWebView.loadUrl(mUrl);
}
 
@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());
        }
    });
}
 
源代码20 项目: CustomActionWebView   文件: APIWebViewActivity.java
/**
 * 1、不在xml中定义Webview,而是在需要的时候在Activity中创建
 * 使用getApplicationgContext(),避免内存泄漏。
 * <p>
 * 2、当然,你也可以配置webView所在Activity,
 * 在AndroidManifest中的进程为:android:process=":remote"
 * 避免泄漏影响主进程
 **/
void addWebViewToLayout() {
    mRootLayout = (FrameLayout) findViewById(R.id.js_root_layout);
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    mWebView = new WebView(getApplicationContext());
    mWebView.setLayoutParams(params);
    mRootLayout.addView(mWebView);
}