11.1 Android with HTML

9
11.1. With HTML Oum Saokosal Master of Engineering in Information Systems, South Korea 855-12-252-752 [email protected]

Transcript of 11.1 Android with HTML

Page 1: 11.1 Android with HTML

11.1. With HTMLOum Saokosal

Master of Engineering in Information Systems, South Korea855-12-252-752

[email protected]

Page 2: 11.1 Android with HTML

Hyperlink from Android App

• Like in HTML, you can create a hyperlink from normal text, picture, and other views as well.

• Simple Text Link:<TextView

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:autoLink="web" android:text="www.facebook.com"/>

Page 3: 11.1 Android with HTML

• Custom Text Link:<TextView android:layout_width="wrap_content"

android:layout_height="wrap_content"android:onClick="gotoWeb"android:clickable="true"android:text="Click Here"/>

in Java:public void gotoWeb(View v){

Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://www.google.com")); startActivity(intent);}

Page 4: 11.1 Android with HTML

• Link on Image:<ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/bird" android:onClick="gotoWeb"/>

in Java:public void gotoWeb(View v){

Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://www.google.com")); startActivity(intent);}

Page 5: 11.1 Android with HTML
Page 6: 11.1 Android with HTML

Generate HTML page1. In main.xml:

<WebView android:id="@+id/webView1" android:layout_width="match_parent" android:layout_height="150dp" />

2. In java:StringBuffer page = new StringBuffer();page.append("<html><body> Welcome to My");page.append("<a

href='http://kohsantepheapdaily.com.kh'>");page.append("Koh News</a></body></html>"); WebView browser = (WebView)

findViewById(R.id.webView1);browser.loadDataWithBaseURL(null, page.toString(),

"text/html", "UTF-8", null);

Page 7: 11.1 Android with HTML

//Complete code//please do import yourself

public class WithHTML extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); StringBuffer page = new StringBuffer();

page.append("<html><body>" + "Welcome to My <a href='http://kohsantepheapdaily.com.kh'>" + "Koh News</a></body></html>"); WebView browser = (WebView) findViewById(R.id.webView1); browser.loadDataWithBaseURL(null, page.toString(), "text/html",

"UTF-8", null);}

public void gotoWeb(View v){Intent intent = new Intent(Intent.ACTION_VIEW);intent.setData(Uri.parse("http://www.google.com"));

startActivity(intent);}

}

Page 8: 11.1 Android with HTML

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:padding="10dip">

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="gotoWeb" android:clickable="true" android:text="Click Here" /> <TextView

android:layout_width="wrap_content" android:layout_height="wrap_content" android:autoLink="web" android:text="www.facebook.com" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/bird" android:onClick="gotoWeb" /> <WebView android:id="@+id/webView1" android:layout_width="match_parent" android:layout_height="150dp" /> </LinearLayout>

Page 9: 11.1 Android with HTML