Android studio點擊跳轉(zhuǎn)WebView詳解
更新時間:2017年09月27日 11:42:20 作者:飛鳥96
這篇文章主要為大家詳細(xì)介紹了Android studio點擊跳轉(zhuǎn)WebView的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了Android studio點擊跳轉(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)頁控件的ID*/
webv=(WebView)findViewById(R.id.web);
/*new一個字符串*/
sb=new StringBuffer("http://www.baidu百度百度.com");
/*刪除包含16 不包含20的字符串*/
sb.delete(16,20);
/*把截取的字符串寫入文字id里*/
tv1.setText(sb);
/*文字點擊事件*/
tv1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
webv.getSettings().setJavaScriptEnabled(true);
webv.loadUrl("https://www.baidu.com");
/*網(wǎng)頁*/
webv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//返回值是true的時候控制去WebView打開,為false調(diào)用系統(tǒng)瀏覽器或第三方瀏覽器
view.loadUrl(url);
return true;
}
});
}
});
}
}
頁面布局
<?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>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android?RecyclerView實現(xiàn)九宮格效果
這篇文章主要為大家詳細(xì)介紹了Android?RecyclerView實現(xiàn)九宮格效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-06-06
Android應(yīng)用中實現(xiàn)手勢控制圖片縮放的完全攻略
這篇文章主要介紹了Android應(yīng)用中實現(xiàn)手勢控制圖片縮放的完全攻略,采用了Matrix矩陣的方法,實例講解了包括觸摸點設(shè)置與各種沖突的處理等方面,相當(dāng)全面,需要的朋友可以參考下2016-04-04
Android 對話框(Dialog)大全示例(建立你自己的對話框)
android開發(fā)中,對話框的使用還是很平凡的,本篇文章介紹了Android 對話框的實例,詳細(xì)的介紹了多種對話框的方法,有興趣的可以了解一下。2016-11-11
Android程序開發(fā)之Listview下拉刷新上拉(滑動分頁)加載更多
這篇文章主要介紹了Android程序開發(fā)之Listview下拉刷新上拉(滑動分頁)加載更多的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-07-07

