我是一个初学者,我使用barteksc库制作pdf查看器,我可以保存书签页面并使用SharedPreferences转到它,如何仅在书签页面上将书签图标添加为ImageView。 我使用此代码,但所有PDF页面上都显示了书签图标。
pdfView.fromAsset("sample.pdf")
// .spacing(10)
.enableSwipe(true) // allows to block changing pages using swipe
.enableDoubletap(true)
.defaultPage(page)
/*.scrollHandle(new DefaultScrollHandle(this))*/
.pageFitPolicy(FitPolicy.WIDTH)
.spacing(10) // in dp
.pages(arrayOfPages)//start from last page to support Right to left navigation
.swipeHorizontal(true)
.pageSnap(true) //scroll through single pages like a ViewPager
.autoSpacing(true) //scroll through single pages like a ViewPager
.pageFling(true) //scroll through single pages like a ViewPager
.enableAntialiasing(true) // improve rendering a little bit on low-res screens
.enableAnnotationRendering(true)
.onRender(new OnRenderListener() {
@Override
public void onInitiallyRendered(int nbPages) {
pdfView.fitToWidth(pdfView.getCurrentPage());
}
})
.load();
}
}
//Menu Items
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu1, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.save_bookmark) {
int bookmarkedPage = pdfView.getCurrentPage();
//TODO add save bookmark button
//bookmarkedPage is the page which has bookmark
SharedPreferences.Editor editor = getSharedPreferences(BOOKMARKS_PREFERENCES, MODE_PRIVATE).edit();
editor.putBoolean("itemID", true);
editor.putInt("bookmarkedPageNum", bookmarkedPage);
editor.apply();
Toast.makeText(this, "Save bookMark", Toast.LENGTH_SHORT).show();
}
if (id == R.id.goTo_bookmark) {
//TODO load page saved in share preferance
SharedPreferences preferences = getSharedPreferences(BOOKMARKS_PREFERENCES, MODE_PRIVATE);
boolean isBookmark = preferences.getBoolean("itemID", false);
int bookmarkedPage = preferences.getInt("bookmarkedPageNum", 0);
pdfView.jumpTo(bookmarkedPage, true);
Toast.makeText(this, " bookMark", Toast.LENGTH_SHORT).show();
// the bookmarked icon
if( bookmarkedPage == pdfView.getCurrentPage()) {
bookmarkIcon.setVisibility(View.VISIBLE);
}
}
return super.onOptionsItemSelected(item);
}
}
有没有办法使书签图标仅显示在加书签的页面上?