سلام دوست عزیز اگه میخوای یه کتاب بنویسی و میخوای کلماتی که توش مینویسی فارسی نمایش بدن میتونی این کد رو توی جاوا بنویسی
البته مسیر Html من در پوشه ی asset توی فولدر asset پوشه ای به نام content هستش
و در قسمت پایین اسم اون جایی که میخوام متنو بنویسم session2 هستش ادامشو برات تو پیام بعدی مینویسم
کد پیاچپی:
book = (ViewGroup) findViewById(R.id.book);
//testTextView();
testWebView();
}
private void testWebView() {
String content = readContent("content/session2.html");
final WebView webView = new WebView(this);
book.addView(webView);
webView.loadDataWithBaseURL("file:///android_asset/", content, "text/html", "UTF-8", "");
}
private void testTextView() {
String content = readContent("content/session2.html");
final TextView textView = new TextView(this);
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setGravity(Gravity.RIGHT);
textView.setLinksClickable(true);
textView.setText(Html.fromHtml(content));
book.addView(textView);
}
private String readContent(String contentUrl) {
InputStream inputStream = null;
try {
inputStream = getResources().getAssets().open(contentUrl);
String sample = streamToString(inputStream);
return sample;
}
catch (IOException e) {
e.printStackTrace();
} finally {
if (inputStream != null) {
try {
inputStream.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
private String streamToString(InputStream inputStream) {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder stringBuffer = new StringBuilder();
String line = null;
try {
while ((line = bufferedReader.readLine()) != null) {
stringBuffer.append((line + "\n"));
}
}
catch (IOException e) {
e.printStackTrace();
} finally {
try {
inputStream.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
return stringBuffer.toString();
البته مسیر Html من در پوشه ی asset توی فولدر asset پوشه ای به نام content هستش
کد پیاچپی:
"file:///android_asset/", content, "text/html"
و در قسمت پایین اسم اون جایی که میخوام متنو بنویسم session2 هستش ادامشو برات تو پیام بعدی مینویسم
کد پیاچپی:
String content = readContent("content/session2.html");