在webview中更改网页的背景颜色

时间:2015-11-12 19:23:01

标签: android webview

我希望在Webview中加载网页后更改网页的背景颜色。但在以不同的方式尝试之后,似乎没有任何工作。 我知道我的代码有点混乱,对不起。

 package com.example.webviewdemo;

    import android.app.Activity;
    import android.graphics.Color;
    import android.os.Bundle;
    import android.view.KeyEvent;
    import android.view.Menu;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.FrameLayout;

    public class MainActivity extends Activity {
    WebView wb;
    //FrameLayout frame;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
            //setTheme(R.style.MyTheme);
            //frame=(FrameLayout) findViewById(R.id.frame);
            wb=(WebView) this.findViewById(R.id.show);
        //wb=new WebView(this);
        //setContentView(wb);
            wb.getSettings().setJavaScriptEnabled(true);
            wb.getSettings().setSupportZoom(true);
            //wb.getSettings().setDefaultTextEncodingName("utf-8");
            //wb.getSettings().set
            wb.setBackgroundColor(Color.BLACK);
            //wb.loadUrl();

            //wb.setBackgroundResource(Color.BLUE);
        //  wb.getBackground().setAlpha(100);
            //wb.loadDataWithBaseURL(null, "¼ÓÔØÖÐ", "text/html", "utf-8", null);
            //wb.loadDataWithBaseURL(mGetDetail., data, mimeType, encoding, historyUrl)
            wb.loadUrl("http://www.baidu.com");
            //wb.loadUrl("<"+"link rel="+\"stylesheet\" href="file:///android_asset/css.css" type="text/css" />")
        //  wb.setVisibility(View.VISIBLE);

            wb.loadUrl("<link rel=\"stylesheet\" href=\"file:///assets/style.css\" type=\"text/css\" />");
            //  wb.setVisibility(View.VISIBLE); // ¼ÓÔØÍêÖ®ºó½øÐÐÉèÖÃÏÔʾ£¬ÒÔÃâ¼ÓÔØʱ³õʼ»¯Ð§¹û²»ºÃ¿´



            wb.setWebViewClient(new WebViewClient(){

                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    // TODO Auto-generated method stub

                    view.loadUrl(url);
                    return true;
                }

            });
            //setContentView(wb);
            //frame.setBackgroundColor(Color.BLACK);

    }


        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            // wb=new WebView(this);
                    wb=(WebView) this.findViewById(R.id.show);
            if(keyCode==KeyEvent.KEYCODE_BACK){
                wb.goBack();
            }
            return true;

        }


        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }

    }

0 个答案:

没有答案