Created
July 12, 2016 04:44
-
-
Save alvareztech/adc373bf3e2ccf968c89fe03a50aca41 to your computer and use it in GitHub Desktop.
Aplicación ejemplo de uso de WebView y Chrome Custom Tabs del curso de desarrollo de aplicaciones Android.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical" | |
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="tech.alvarez.ejemploweb.MainActivity"> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="48dp" | |
android:onClick="abrir" | |
android:text="@string/abrirWeb" /> | |
<WebView | |
android:id="@+id/webView" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" /> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// build.gradle del módulo | |
apply plugin: 'com.android.application' | |
android { | |
compileSdkVersion 24 | |
buildToolsVersion "24.0.0" | |
defaultConfig { | |
applicationId "tech.alvarez.ejemploweb" | |
minSdkVersion 15 | |
targetSdkVersion 24 | |
versionCode 1 | |
versionName "1.0" | |
} | |
buildTypes { | |
release { | |
minifyEnabled false | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | |
} | |
} | |
} | |
dependencies { | |
compile fileTree(dir: 'libs', include: ['*.jar']) | |
testCompile 'junit:junit:4.12' | |
compile 'com.android.support:appcompat-v7:24.0.0' | |
compile 'com.android.support:customtabs:24.0.0' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tech.alvarez.ejemploweb; | |
import android.net.Uri; | |
import android.os.Bundle; | |
import android.support.customtabs.CustomTabsIntent; | |
import android.support.v4.content.ContextCompat; | |
import android.support.v7.app.AppCompatActivity; | |
import android.view.View; | |
import android.webkit.WebView; | |
public class MainActivity extends AppCompatActivity { | |
private WebView webView; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
webView = (WebView) findViewById(R.id.webView); | |
String html = "<html><body><h2>Un título</h2>Este es un <b>ejemplo</b> de contenido.</body></html>"; | |
webView.loadData(html, "text/html; charset=utf-8", null); | |
} | |
public void abrir(View view) { | |
String url = "http://alvarez.tech/cursos/android"; | |
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); | |
builder.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary)); | |
CustomTabsIntent customTabsIntent = builder.build(); | |
customTabsIntent.launchUrl(this, Uri.parse(url)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<resources> | |
<string name="app_name">EjemploWeb</string> | |
<string name="abrirWeb">Abrir Web</string> | |
</resources> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment