最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android studio點(diǎn)擊跳轉(zhuǎn)WebView詳解

 更新時(shí)間:2017年09月27日 11:42:20   作者:飛鳥(niǎo)96  
這篇文章主要為大家詳細(xì)介紹了Android studio點(diǎn)擊跳轉(zhuǎn)WebView的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android studio點(diǎn)擊跳轉(zhuǎn)WebView的具體代碼,供大家參考,具體內(nèi)容如下

代碼文件

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
  private StringBuffer sb;/*截取字符串*/
  private TextView tv1;
  private WebView webv;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    /*獲取文字的ID*/
    tv1=(TextView)findViewById(R.id.wang);
    /*獲取網(wǎng)頁(yè)控件的ID*/
    webv=(WebView)findViewById(R.id.web);
    /*new一個(gè)字符串*/
    sb=new StringBuffer("http://www.baidu百度百度.com");
    /*刪除包含16 不包含20的字符串*/
    sb.delete(16,20);
    /*把截取的字符串寫(xiě)入文字id里*/
    tv1.setText(sb);
    /*文字點(diǎn)擊事件*/
    tv1.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
        webv.getSettings().setJavaScriptEnabled(true);
        webv.loadUrl("https://www.baidu.com");
        /*網(wǎng)頁(yè)*/
        webv.setWebViewClient(new WebViewClient() {
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            //返回值是true的時(shí)候控制去WebView打開(kāi),為false調(diào)用系統(tǒng)瀏覽器或第三方瀏覽器
            view.loadUrl(url);
            return true;
          }
        });
      }
    });
  }
}

頁(yè)面布局 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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: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="你的包名地址.MainActivity">
  <TextView
    android:id="@+id/wang"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="www.baidu.com"
    android:layout_centerHorizontal="true"
    />
  <RelativeLayout
    android:id="@+id/l1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/wang"
    android:layout_centerHorizontal="true"
    >
    <TextView
      android:id="@+id/ba"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="百度"
      />
    <ImageView
      android:id="@+id/img"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:src="@drawable/ic_launcher"
      android:layout_toRightOf="@id/ba"
      />
    <TextView
      android:id="@+id/yu"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="百度"
      android:layout_toRightOf="@id/img"
      />
  </RelativeLayout>
  <WebView
    android:id="@+id/web"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/l1"
    >
  </WebView>
</RelativeLayout>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

大洼县| 波密县| 昔阳县| 门头沟区| 墨江| 靖宇县| 达州市| 文安县| 广昌县| 乐陵市| 河池市| 红河县| 兴和县| 新巴尔虎右旗| 鄂托克旗| 永清县| 闸北区| 江西省| 中方县| 东平县| 永修县| 桦甸市| 融水| 兰西县| 娱乐| 兴和县| 东乡族自治县| 洞头县| 太仆寺旗| 晋中市| 潼关县| 宁远县| 镇赉县| 江孜县| 班戈县| 广州市| 隆尧县| 山西省| 兴文县| 定兴县| 许昌县|