WebView Control Android
************************** Main.xml *******************************
<?xml version="1.0" encoding="utf-8"?>
<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"
android:orientation="vertical"
tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GO"
android:id="@+id/btn"/>
<WebView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="@+id/web"/>
</LinearLayout>
************************** main.java *************************
package com.example.web;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button ok;
WebView view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ok=(Button) findViewById(R.id.btn);
view=(WebView) findViewById(R.id.web);
ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
/* Intent intent=new Intent(Intent.ACTION_VIEW, Uri.parse("http://google.com"));
startActivity(intent);*/
view.loadUrl("http://google.com");
}
});
}
}
0 Comments