图文混排加webview跳转

来源:互联网 发布:数控铣削平面编程实例 编辑:程序博客网 时间:2024/06/08 11:34
package com.bwei.test.wangyajie1508a20170627;import android.graphics.Paint;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.webkit.WebSettings;import android.webkit.WebView;import android.webkit.WebViewClient;import android.widget.Button;import android.widget.TextView;import static com.bwei.test.wangyajie1508a20170627.R.id.webview;public class MainActivity extends AppCompatActivity {    Button btn;    WebView webView;    TextView textView;    String str = "http://www.baidu文字.com";    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        textView = (TextView) findViewById(R.id.tv);        btn = (Button) findViewById(R.id.btn);        webView = (WebView) findViewById(webview);        //        Toast.makeText(MainActivity.this,str,Toast.LENGTH_SHORT).show();        final String s = str.replace("文字", "");//        Toast.makeText(MainActivity.this, s, Toast.LENGTH_SHORT).show();        textView.setText(s);        textView.getPaint().setFlags(Paint. UNDERLINE_TEXT_FLAG );        btn.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {//                Toast.makeText(MainActivity.this, "113121", Toast.LENGTH_SHORT).show();                webView.setVisibility(View.VISIBLE);                WebSettings settings = webView.getSettings();                settings.setJavaScriptEnabled(true);                webView.loadUrl(s);                webView.setWebViewClient(new WebViewClient(){                    @Override                    public boolean shouldOverrideUrlLoading(WebView view, String url) {                        view.loadUrl(url);                        return true;                    }                });            }        });    }}
<?xml version="1.0" encoding="utf-8"?><LinearLayout    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/activity_main"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context="com.bwei.test.wangyajie1508a20170627.MainActivity">    <TextView        android:id="@+id/tv"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Hello World!"/>    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content">        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="文字-"/>        <ImageView            android:background="@mipmap/ic_launcher"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            />        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="-文字"/>    </LinearLayout>    <Button        android:id="@+id/btn"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="baidu"/>    <WebView        android:id="@+id/webview"        android:layout_width="wrap_content"        android:layout_height="wrap_content">    </WebView></LinearLayout>