久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何更改 EditText 光標高度?

How to change EditText cursor height?(如何更改 EditText 光標高度?)
本文介紹了如何更改 EditText 光標高度?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我想改變 EditText 光標高度,有人知道怎么做嗎?

I want to change the EditText cursor height, does anyone know how?

推薦答案

我不得不深入研究 Android 源代碼才能找到答案,但實際上您必須在自定義形狀可繪制對象上使用填充.

I had to dig far into the Android source to find the answer to this, but you essentially have to use padding on a custom shape drawable.

注意:僅適用于 API 12 及更高版本,因為支持 textCursorDrawable

使用 positive top 內邊距將光標的 top 移動更高

Use positive top padding to move the top of your cursor higher

用戶 bottom填充移動光標的底部降低

我通常最終使用負底部填充來縮短光標,因為當您使用 lineSpacingMultiplierlineSpacingExtra 增加行高時,光標會下降到低于基線的位置.

I usually end up using negative bottom padding to shorten the cursor because the it drops too low below baseline when you increase the line height with lineSpacingMultiplier or lineSpacingExtra.

cursor_red.xml 示例:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <size 
        android:width="2dip" />
    <solid
        android:color="@color/red" />
    <padding 
        android:top="2sp"
        android:bottom="-11sp" />
</shape>

這將生成一個 2dip 寬的紅色光標

This will make a 2dip wide red cursor that is

  • 頂部高出 2sp(更長)
  • 底部高出(短)11sp.

然后在你的edittext中,指定android:textCursorDrawable:

Then in your edittext, just specify android:textCursorDrawable:

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textCursorDrawable="@drawable/cursor_red" />

Editor.java中的相關Android源代碼,我從中找到了解決方案:

Relevant Android source code inside Editor.java from which I figured out the solution:

private void updateCursorPosition(int cursorIndex, int top, int bottom, float horizontal) {
    ...

    mCursorDrawable[cursorIndex].getPadding(mTempRect);

    ...

    mCursorDrawable[cursorIndex].setBounds(left, top - mTempRect.top, left + width,
            bottom + mTempRect.bottom);
}

這篇關于如何更改 EditText 光標高度?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cut, copy, paste in android(在android中剪切、復制、粘貼)
android EditText blends into background(android EditText 融入背景)
Change Line Color of EditText - Android(更改 EditText 的線條顏色 - Android)
EditText showing numbers with 2 decimals at all times(EditText 始終顯示帶 2 位小數的數字)
Changing where cursor starts in an expanded EditText(更改光標在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 国产美女久久 | 天天操欧美 | av片免费| 国产永久免费 | 国产免费一区二区三区网站免费 | 一级全黄少妇性色生活免费看 | 国产欧美日韩综合精品一区二区 | 美女视频一区二区三区 | 国产一区二区久久久 | 亚洲黄色网址视频 | 欧美成人免费在线 | 精品国产一区二区三区久久久久久 | 免费黄色特级片 | 欧美黄在线观看 | 久久亚洲精品国产精品紫薇 | 中文字幕视频在线观看 | 欧美日韩国产高清视频 | 天堂久久av | 亚洲一区二区三区在线播放 | 亚洲国产精品一区二区三区 | 人人人人干 | 日韩在线观看中文字幕 | 欧美视频免费在线 | 国产精品99久久久久久人 | 久久久久久久一区二区三区 | a精品视频 | 国产精品免费小视频 | 国产精品色婷婷久久58 | 日日骚av| 在线天堂免费中文字幕视频 | 欧美精品一区二区三区四区 | 国产日韩欧美激情 | 5060网一级毛片 | 荷兰欧美一级毛片 | 国内精品在线视频 | 自拍偷拍第1页 | 欧美一级淫片免费视频黄 | 毛片一级片 | 欧美日韩三级 | www成年人视频 | 亚洲天堂精品一区 |