Android隨筆之——獲取EditText光標所在行行號


  由於項目需求,需要獲取EditText光標當前所在行行號,可是翻遍Android文檔、問遍度娘都沒發現,於是在博客園中提問,碰見了好心人告訴了我答案,謹以以下代碼獻給有需要的人

  

1 private int getCurrentCursorLine(EditText editText) {
2         int selectionStart = Selection.getSelectionStart(editText.getText());
3         Layout layout = editText.getLayout();
4 
5         if (selectionStart != -1) {
6             return layout.getLineForOffset(selectionStart) + 1;
7         }
8         return -1;
9     }

 

作者:登天路

轉載請說明出處:http://www.cnblogs.com/travellife/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM