martes, 19 de diciembre de 2017

WEBVIEW ANDROID


1) Add component webView on your layout

activity_main.xml
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout 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="com...MainActivity">
    <LinearLayout        android:layout_width="match_parent"        android:layout_height="match_parent"        android:orientation="vertical">
        <WebView
            android:id="@+id/webView"
            android:layout_width="match_parent"
            android:layout_height="440dp"
            tools:layout_editor_absoluteX="8dp"
            tools:layout_editor_absoluteY="16dp" />
    </LinearLayout>

</android.support.constraint.ConstraintLayout>


2) use LoadUrl to show the content :
MainActivity.java
package com..;
import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.webkit.WebView;


public class MainActivity extends AppCompatActivity {

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);
        WebView myWebView = (WebView) this.findViewById(R.id.webView);
        myWebView.loadUrl("http://https://jgvcodigo.blogspot.com/");
    }
}

3) You are going to need to add some permission to your Manifest:

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com..">
    <uses-permission android:name="android.permission.INTERNET" />
    <application        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"        android:roundIcon="@mipmap/ic_launcher_round"        android:supportsRtl="true"        android:theme="@style/AppTheme">        <activity android:name=".MainActivity">            <intent-filter>                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application>
</manifest>








https://amatellanes.wordpress.com/2013/06/08/android-ejemplo-de-webview-en-android-parte-2/

No hay comentarios:

Publicar un comentario