问题

Here I want to highlight this text using onTouchevent in android
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/9173164/how-to-highlight-this-pdf-page-using-ontouchevent-in-android