gpt4 book ai didi

android - android 中 epub 的字体大小?

转载 作者:行者123 更新时间:2023-11-30 02:41:23 24 4
gpt4 key购买 nike

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

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

我需要为设置 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);
}
}
}

最佳答案

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

WebSettings webSettings = webView.getSettings();

setTextSize 或

webSettings.setTextSize(WebSettings.TextSize.SMALLEST);

这个也行:-

webSettings.setDefaultFontSize(10);

谢谢

关于android - android 中 epub 的字体大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25709497/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com