Local Html file မ်ားကို WebView တြင္ ေဖာ္ျပျခင္း (၁)
=============
ကိုယ့္ app ထဲမွာ စာနဲ႔ ရုပ္ပံုေတြကို ဒီဇိုင္းအမ်ိဳးမ်ိဳးနဲ႔ (pdf page ေတြလိုမ်ိဳး) ေဖာ္ျပခ်င္ရင္ WebView နဲ႔ local html file ေတြ image file ေတြကို assets folder ထဲမွာ ထားၿပီး ေဖာ္ျပႏိုင္ပါတယ္။ WebView ရဲ့ လုပ္ေဆာင္ႏိုင္စြမ္းကို ေလွ်ာ့မတြက္ပါနဲ႔။
အခု project မွာ စာေတြနဲ႔ ပံု ၃ ပံုကို html ဖိုင္ကေန တဆင့္ WebView ထဲကို ဆြဲတင္ပံုကို နမူနာ ေရးျပထားပါတယ္။
၁။ src/main/assets folder ကိုေဆာက္ပါ။ အဲဒီထဲမွာ html, css, javascript file ေတြကို ထည့္ထားမွာ ျဖစ္ပါတယ္။
၂။ src/main/assets/images folder ကို ေဆာက္ပါ။ အဲဒီထဲမွာ html file ေတြက သံုးမဲ့ image file ေတြကို ထည့္ထားမွာ ျဖစ္ပါတယ္။
၃။ html file ကေန image file ကို ေအာက္က လို အသံုးျပဳရပါတယ္။
<img src='images/bomb.jpg' width='100%'>
၄။ WebView မွာ html file ကို ေအာက္ကလို ဆြဲတင္ပါတယ္။
wv.loadUrl("file:///android_asset/page1.html");
၅။ ကဲ။ စပါမယ္။
src/main/assets/page1.html
=================
<body>
"The pen is mightier than the sword."
<br>
Tweet This! Trying to convince people with ideas and words is more effective than trying to force people to do what you want.
<br>
<img src='images/bomb.jpg' width='100%'><br>
"When in Rome, do as the Romans."
<br>
Tweet This! Act the way that the people around you are acting. This phrase might come in handy when you're traveling abroad notice that people do things differently than you're used to.
<br>
<img src='images/add.png' width='100%'><br>
"When the going gets tough, the tough get going."<br>
Tweet This! Strong people don't give up when they come across challenges. They just work harder.
<br>
<img src='images/next.png' width='100%'><br>
</body>
===============
၆။ src/main/assets/images filder ထဲမွာ bomb.jpg, add.png နဲ႔ next.png ၃ဖိုင္ကို ထည့္ထားပါတယ္။
၇။ MainActivity.java
=================
package nnl.aide.lessons;
import android.app.*;
import android.os.*;
import android.webkit.*;
public class MainActivity extends Activity
{
WebView wv;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
wv=(WebView)findViewById(R.id.wv);
wv.loadUrl("file:///android_asset/page1.html");
}
}
===========
၈။ main.xml
==========
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<WebView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/wv"/>
</LinearLayout>
===========
လက္ေတြ႕ လုပ္ျဖစ္ေအာင္ project source file မတင္ေတာ့ဘူးေနာ္။
Comments
Post a Comment