如何在android中使用Ontouchevent突出显示此pdf页面

发布于 2025-01-03 13:05:37 字数 101 浏览 2 评论 0原文

这里我想使用android中的onTouchevent突出显示这段文本

Here I want to highlight this text using onTouchevent in android

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

等你爱我 2025-01-10 13:05:37

您可以使用 OnTouchListener 来获取事件的 x 和 y。然后将屏幕绘制为位图,并根据字母的左上角显示和字母的大小使用bitmap.getPixel,看看它旁边的下一个字母是否也不是空格。最后,放一个黄色白色和黑色字母之间的矩形或您希望突出显示的矩形。

You could use OnTouchListener to get the x and y of the event. Then drawing the screen to a bitmap and using bitmap.getPixel based on the top left display of the letter nd the size of your letters, to see if the next letter(s) next to it are also not spaces.Finally, put a yellow rectangle in between the white and the black lettering or the ones you wish to have highlighted.

无人接听 2025-01-10 13:05:37

您必须为按钮或任何您想要的视图实现 onTouchListener。
如下所示:

实现 OnTouchListener:

public class DrawingActivity extends Activity implements View.OnTouchListener

然后实现查看触摸操作的代码:

 public boolean onTouch(View view, MotionEvent motionEvent) {

    if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){

    }else if(motionEvent.getAction() == MotionEvent.ACTION_MOVE){

    }else if(motionEvent.getAction() == MotionEvent.ACTION_UP){


    }

    return true;
}

现在添加用于打开 pdf 的代码到相应的操作中。
请参阅打开的 pdf 示例:

File file = new File("/sdcard/YOUR_PDF_FILE_PATH_WITH_NAME.pdf"); // give the path of your pdf file
                Uri path = Uri.fromFile(file);
                Intent intentPDF = new Intent(Intent.ACTION_VIEW);                     
                intentPDF.setDataAndType(path, "application/pdf");                     
                intentPDF.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);                      
                try {                         
                    startActivity(intentPDF);                     
                }                      
                catch (ActivityNotFoundException e) {                         
                    Toast.makeText(ListSample.this,                              
                         "No Application Available to View PDF",                              
                         Toast.LENGTH_SHORT).show();                     
                }       

希望它会对您有所帮助。如果没有,请告诉我。

You have to implement the onTouchListener for the button or any view you want.
as like below:

implement the OnTouchListener:

public class DrawingActivity extends Activity implements View.OnTouchListener

Then implement the code for view touch action:

 public boolean onTouch(View view, MotionEvent motionEvent) {

    if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){

    }else if(motionEvent.getAction() == MotionEvent.ACTION_MOVE){

    }else if(motionEvent.getAction() == MotionEvent.ACTION_UP){


    }

    return true;
}

Now add the code to open the pdf in to respective action.
See this Example for the open pdf:

File file = new File("/sdcard/YOUR_PDF_FILE_PATH_WITH_NAME.pdf"); // give the path of your pdf file
                Uri path = Uri.fromFile(file);
                Intent intentPDF = new Intent(Intent.ACTION_VIEW);                     
                intentPDF.setDataAndType(path, "application/pdf");                     
                intentPDF.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);                      
                try {                         
                    startActivity(intentPDF);                     
                }                      
                catch (ActivityNotFoundException e) {                         
                    Toast.makeText(ListSample.this,                              
                         "No Application Available to View PDF",                              
                         Toast.LENGTH_SHORT).show();                     
                }       

Hope it will helps you. If not then let me know.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文