انجمن سایت کلیدستان


رتبه موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
عدم نمایش کلمات فارسی در webview (در برنامه نویسی اندروید)

عدم نمایش کلمات فارسی در webview (در برنامه نویسی اندروید)

#5
سلام دوست عزیز اگه میخوای یه کتاب بنویسی و میخوای کلماتی که توش مینویسی فارسی نمایش بدن میتونی این کد رو توی جاوا بنویسی

کد پی‌اچ‌پی:
book = (ViewGroupfindViewById(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"); 
پاسخ
 سپاس شده توسط admin


پیام‌های این موضوع
RE: عدم نمایش کلمات فارسی در webview (در برنامه نویسی اندروید) - توسط amirhosseinpro - ۱۳۹۴/۰۳/۳۱, ۰۳:۳۹ ب.ظ

پرش به انجمن:


کاربران در حال بازدید این موضوع: 1 مهمان