日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > Android >内容正文

Android

Android 访问网页

發(fā)布時(shí)間:2025/3/15 Android 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android 访问网页 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1. 配置網(wǎng)絡(luò)訪問(wèn)權(quán)限?

? 修改項(xiàng)目根目錄中AndroidManifest.xml資源配置文件, 添加對(duì)Internet 訪問(wèn)權(quán)限:

? <uses-permission?android:name="android.permission.INTERNET"></uses-permission>?

全局 AndroidManifest.xml 清單如下:?

?<?xml?version="1.0"?encoding="utf-8"?>

<manifest?xmlns:android="http://schemas.android.com/apk/res/android"
??????package
="com.test.android"
??????android:versionCode
="1"
??????android:versionName
="1.0">
????
<application?android:icon="@drawable/icon"?android:label="@string/app_name">
????????
<activity?android:name=".FirstAppUI"?android:label="@string/app_name">
????????????
<intent-filter>
????????????????
<action?android:name="android.intent.action.MAIN"?/>
????????????????
<category?android:name="android.intent.category.LAUNCHER"?/>
????????????
</intent-filter>
????????
</activity>
????
</application>
????
<uses-permission?android:name="android.permission.INTERNET"></uses-permission>
????
<uses-sdk?android:minSdkVersion="8"?/>
</manifest>?

?

2. 修改 layout\main.xml 布局文件

?

<?xml?version="1.0"?encoding="utf-8"?>
<AbsoluteLayout?
??
xmlns:android="http://schemas.android.com/apk/res/android"
??android:orientation
="vertical"
??android:layout_width
="fill_parent"
??android:layout_height
="fill_parent"?>

?
<EditText
??
android:id="@+id/editText01"?
??android:layout_width
="200px"
??android:layout_height
="40px"
??android:textSize
="18sp"
??android:layout_x
="5px"
??android:layout_y
="32px"?/>
?
<Button
??
android:id="@+id/button01"
??android:layout_width
="60px"
??android:layout_height
="40px"
??android:text
="轉(zhuǎn)到"
??android:layout_x
="205px"
??android:layout_y
="35px"
??
/>
?<WebView?
??android:id="@+id/webView01"?
??android:layout_height
="330px"?
??android:layout_width
="300px"?
??android:layout_x
="7px"
??android:layout_y
="90px"
??android:focusable
="false"
??
/>?

</AbsoluteLayout>?

?

3. MainActivity.java 的 onCreate() 方法中添加對(duì)網(wǎng)絡(luò)的訪問(wèn)

?

private?Button?button;
private?EditText?editText;
private?WebView?webView;

@Override
public?void?onCreate(Bundle?savedInstanceState)?{
????
super.onCreate(savedInstanceState);
????setContentView(R.layout.main);

????
//?獲得布局中的控件
????button=?(Button)?findViewById(R.id.button01);
????editText?
=?(EditText)?findViewById(R.id.editText01);
????webView?
=?(WebView)?findViewById(R.id.webView01);

????
//?查詢(xún)按鈕添加事件
????button.setOnClickListener(new?Button.OnClickListener()?{
????????
public?void?onClick(View?arg0)?{
????????????String?strURL?
=?(editText.getText().toString());
????????????strURL?
=?strURL.trim();
????????????
????????????
if?(strURL.length()?==?0)?{
????????????????Toast.makeText(MainActivity.
this,?"查詢(xún)內(nèi)容不能為空!",Toast.LENGTH_LONG).show();
????????????}
????????????
else?{
????????????????webView.loadUrl(strURL);
????????????}
????????}
????});

}?

轉(zhuǎn)載于:https://www.cnblogs.com/Yuqui1980/archive/2011/08/02/2124989.html

總結(jié)

以上是生活随笔為你收集整理的Android 访问网页的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。