Created
November 6, 2016 02:04
-
-
Save alvareztech/110addc00b537a16ee6216f38c7755a4 to your computer and use it in GitHub Desktop.
Ejemplo Web. Curso de desarrollo de aplicaciones Android
This file contains hidden or 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:id="@+id/activity_main" | |
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.ejemplowebview.MainActivity"> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:onClick="abrirPaginaWeb" | |
android:text="@string/abrir_pagina_web" /> | |
<WebView | |
android:id="@+id/paginaWebView" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" /> | |
</LinearLayout> |
This file contains hidden or 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
apply plugin: 'com.android.application' | |
android { | |
compileSdkVersion 25 | |
buildToolsVersion "25.0.0" | |
defaultConfig { | |
applicationId "tech.alvarez.ejemplowebview" | |
minSdkVersion 15 | |
targetSdkVersion 25 | |
versionCode 1 | |
versionName "1.0" | |
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | |
} | |
buildTypes { | |
release { | |
minifyEnabled false | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | |
} | |
} | |
} | |
dependencies { | |
compile fileTree(dir: 'libs', include: ['*.jar']) | |
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { | |
exclude group: 'com.android.support', module: 'support-annotations' | |
}) | |
compile 'com.android.support:appcompat-v7:25.0.0' | |
testCompile 'junit:junit:4.12' | |
compile 'com.android.support:customtabs:25.0.0' | |
} |
This file contains hidden or 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.ejemplowebview; | |
import android.net.Uri; | |
import android.support.customtabs.CustomTabsIntent; | |
import android.support.v4.content.ContextCompat; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.webkit.WebView; | |
public class MainActivity extends AppCompatActivity { | |
private WebView paginaWebView; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
paginaWebView = (WebView) findViewById(R.id.paginaWebView); | |
// paginaWebView.loadUrl("http://alvarez.tech/android-umsa"); | |
String html = "<html><body><h2>Ejemplo</h2><p>Este es un contenido de ejemplo</p></body></html>"; | |
paginaWebView.loadData(html, "text/html; charset-utf-8", null); | |
} | |
public void abrirPaginaWeb(View view) { | |
String url = "http://alvarez.tech/android-umsa"; | |
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); | |
builder.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary)); | |
CustomTabsIntent customTabsIntent = builder.build(); | |
customTabsIntent.launchUrl(this, Uri.parse(url)); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment