The effect is as follows:
** Old custom, finally have the source code.
Steps:
- Add network permissions to the butler file **
2. Super simple WebView implementation: three lines
The code is as follows:
Layout file: **
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:orientation="vertical"> <RelativeLayout android:layout_width="match_parent" android:layout_height="80dp"> <Button android:id="@+id/passon" android:layout_width="61dp" android:layout_height="36dp" Android :layout_alignParentTop="true" Android :layout_alignParentEnd="true" Android :text=" turn in "/> <Button android:id="@+id/themain" android:layout_width="212dp" android:layout_height="37dp" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="0dp" <EditText android:id="@+id/myurl" Android :layout_width="320dp" Android :layout_height="45dp" android:layout_alignParentStart="true" android:layout_alignParentTop="true" android:layout_marginStart="0dp" Android :layout_marginTop="0dp" android:ems="10" Android: Hint =" Android :layout_marginTop="0dp" Android :ems="10" Android :hint=" Android :maxLines="1" /> </RelativeLayout> <WebView android:id="@+id/myweb" android:layout_width="match_parent" android:layout_height="match_parent"> </WebView> </LinearLayout>Copy the code
Java file:
public class MainActivity extends Activity implements View.OnClickListener { private WebView myweb; private String baidu = "http://www.baidu.com"; private Button passon; private Button themain; private EditText myurl; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); myweb.getSettings().setJavaScriptEnabled(true); Myweb.setwebviewclient (new WebViewClient())); // Call the getSettings () method to add properties that enable webView to support JavaScript. // Make it jump and still use webView to display myWeb.loadURL (baidu); } private void initView() {myWeb = (WebView) findViewById(R.i.D.myWeb); passon = (Button) findViewById(R.id.passon); passon.setOnClickListener(this); themain = (Button) findViewById(R.id.themain); themain.setOnClickListener(this); myurl = (EditText) findViewById(R.id.myurl); myurl.setOnClickListener(this); } @override public void onClick(View v) {switch (v.getid ()) {case R.i.D.passon :// String passonUri =myurl.getText().toString(); if (! passonUri.equals("")){ myweb.loadUrl(passonUri); }else{totoast. MakeText (this," please enter the url ", totoast.LENGTH_SHORT).show(); } break; Case R.I.D.temp :// home button myweb.loadURL (baidu); break; }}}Copy the code