Skip to main content
1 de 6

WebView no Android, modificando o HTML

Estou conseguindo carregar o URL no meu dispositivo, usando o WebView, porem a pagina que carrega não é adaptada para dispositivos moveis. Gostaria de saber se tem como eu acessar a pagina porem eliminando algumas partes do HTML. O Codigo do main esta abaixo e o webClient também.

MainActivity.java:

public class MainActivity extends ActionBarActivity {

private WebView mWebView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mWebView = (WebView) findViewById(R.id.wvLogin);

WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);

mWebView.loadUrl("http://siga.ufvjm.edu.br");

mWebView.setWebViewClient(new WebViewClient());

mWebView.setWebViewClient(new MyAppWebViewClient());
}

@Override
public void onBackPressed(){
if(mWebView.canGoBack()){
mWebView.goBack();
} else {
super.onBackPressed();
}
}

MyAppWebViewClient.java :

package com.example.siga;

import android.content.Intent;
import android.net.Uri;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MyAppWebViewClient extends WebViewClient {

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
if(Uri.parse(url).getHost().endsWith("http://siga.ufvjm.edu.br")){
return false;
}

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
view.getContext().startActivity(intent);
return true;
}

}

XML :

<RelativeLayout 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: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="com.example.siga.MainActivity" >

<ImageView
android:id="@+id/ivLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:src="@drawable/logo_siga" />

<WebView
android:id="@+id/wvLogin"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/ivLogo"
android:layout_centerHorizontal="true" />

</RelativeLayout>

Desejo deixar apenas o campo de login e o botão de login. e depois se encaminhado para um nova activty.