Sur android il y a un composant que je trouve vraiment intéressant c’est WebView. Ce composant permet d’utiliser du code html dans notre interface.
D’abord dans mon fichier xml j’ajoute un élément Webview.
Il faut ensuite créer un objet de type WebView.
WebView objetview;
Dans une chaine de caractère on saisie notre code html.
String mapage="Utilisation HTML
Utilisation du code html dans une
webview android";
Dans la méthode loadData de notre objet on passe la chaine de caractère maPage
final String mimeType = "text/html";
final String encoding = "utf-8";
wv.loadData(mapage, mimeType, encoding);
Code complet
public class Newnavigateur extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// les définitions de type mime et de l'encodage
final String mimeType = "text/html";
final String encoding = "utf-8";
WebView objetview;
//mon code html
String mapage="Utilisation HTML
Utilisation du code html dans une
webview android";
objetview= (WebView) findViewById(R.id.eltWebView);
//on charge mon code html dans ma webview
objetview.loadData(mapage, mimeType, encoding);
}
}
Si vous développez souvent en html, ce composant vous permettra de faire une mise en page rapide, par exemple pour la restitution d’information.