android中epubs的字体大小?

时间:2014-09-07 11:02:05

标签: android android-webview epub android-fonts

是否可以在android中为FontSize设置epub boooks可用性?

注意:我在epub显示WebView的数据。

我需要为集FontSize创建一个选项。

public class MainActivity extends ActionBarActivity implements OnClickListener{
    WebView webView;
    Handler hand ;
    String data = null;
    LinearLayout books;
    int pagecount = 1;
    int y = 1;
    Book book;
    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        hand = new Handler();
        webView = new WebView(this);
        webView.getSettings().setJavaScriptEnabled(true);
        books = (LinearLayout) findViewById(R.id.book);
         AssetManager assetManager = getAssets();
         try{
             InputStream epubInputStream = assetManager.open("ok.epub");
             book = (new EpubReader()).readEpub(epubInputStream);
             Log.i("Log_one", "author(s): " + book.getMetadata().getAuthors());
             Log.i("Log_two", "title: " + book.getTitle());
             Bitmap coverImage = BitmapFactory.decodeStream(book.getCoverImage().getInputStream());
             Log.i("Log_three", "Coverimage is " + coverImage.getWidth() + " by " + coverImage.getHeight() + " pixels");
             logTableOfContents(book.getTableOfContents().getTocReferences(), 0);

             Spine spine = book.getSpine(); 
             List<SpineReference> spineList = spine.getSpineReferences() ;
             int count = spineList.size();

             String datas = new String(book.getContents().get(1).getData());
             webView.loadDataWithBaseURL("file:///android_asset/", datas, "text/html", "UTF-8", null);
             books.addView(webView);
             Log.i("Log_four", datas);

         }
         catch (IOException e) {
              Log.e("Log_four", e.getMessage());
            }

         webView.setOnTouchListener(new OnSwipeTouchListener(G.context){
                public void onSwipeTop() {
                    Toast.makeText(MainActivity.this, "top", Toast.LENGTH_SHORT).show();
                }
                public void onSwipeRight() {    
                    try {

                        books.removeAllViews();
                        int i = pagecount + y;
                        y = i;
                            books = (LinearLayout) findViewById(R.id.book);
                            data = new String(book.getContents().get(y).getData());
                            webView.loadDataWithBaseURL("file:///android_asset/", data, "text/html", "UTF-8", null);
                            Log.i("test",String.valueOf(y));
                            books.addView(webView);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                public void onSwipeLeft() {
                    try {
                        if(y >= 1)
                        {
                            int i = y - pagecount;
                            y = i;
                        }
                        if(y >= 1)
                        {
                            books.removeAllViews();
                            books = (LinearLayout) findViewById(R.id.book);
                            data = new String(book.getContents().get(y).getData());
                            webView.loadDataWithBaseURL("file:///android_asset/", data, "text/html", "UTF-8", null);
                            Log.i("test",String.valueOf(y));
                            books.addView(webView);
                        }else if(y == 0)
                        {
                            Toast.makeText(getApplicationContext(), "Zero Page", Toast.LENGTH_LONG).show();
                            Log.i("test",String.valueOf(y));
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                public void onSwipeBottom() {
                    Toast.makeText(MainActivity.this, "bottom", Toast.LENGTH_SHORT).show();
                }

            public boolean onTouch(View v, MotionEvent event) {
                gestureDetector.onTouchEvent(event);
                return false;
            }
         });
    }
      private void logTableOfContents(List<TOCReference> tocReferences, int depth) {
            if (tocReferences == null) {
              return;
            }
            for (TOCReference tocReference : tocReferences) {
              StringBuilder tocString = new StringBuilder();
              for (int i = 0; i < depth; i++) {
                tocString.append("\t");
              }
              tocString.append(tocReference.getTitle());
              Log.i("Log_five", tocString.toString());
              logTableOfContents(tocReference.getChildren(), depth + 1);
            }
          }
}

1 个答案:

答案 0 :(得分:1)

你可以设置android webview的字体大小。

WebSettings webSettings = webView.getSettings();

setTextSize或

webSettings.setTextSize(WebSettings.TextSize.SMALLEST);

这个也适用: -

webSettings.setDefaultFontSize(10);

由于