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

如何更改 EditText 光標(biāo)高度?

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

問題描述

限時送ChatGPT賬號..

我想改變 EditText 光標(biāo)高度,有人知道怎么做嗎?

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 內(nèi)邊距將光標(biāo)的 top 移動更高

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

用戶 bottom填充移動光標(biāo)的底部降低

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

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 寬的紅色光標(biāo)

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中的相關(guān)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);
}

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

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

相關(guān)文檔推薦

Cut, copy, paste in android(在android中剪切、復(fù)制、粘貼)
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 位小數(shù)的數(shù)字)
Changing where cursor starts in an expanded EditText(更改光標(biāo)在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 久久久久国产精品一区二区 | 欧美性jizz18性欧美 | 精品影院 | 国产精品一区二区三区在线 | 久久三级av | 欧美精品一区二区三区蜜桃视频 | 一区二区三区电影网 | 中文字幕在线观看国产 | 一区二区三区视频在线免费观看 | 亚洲一区三区在线观看 | 免费av直接看 | 91电影| 日韩一区二区三区在线观看 | 国产精品免费一区二区 | 美女在线观看av | 一级黄色毛片子 | 亚洲一区久久久 | 欧美色人 | 欧美精品中文字幕久久二区 | 精品国产欧美 | 欧美在线视频不卡 | 久久福利网站 | 俺去俺来也www色官网cms | 99久久婷婷国产亚洲终合精品 | 狠狠的干| 一本久久a久久精品亚洲 | 欧美一区二区三区久久精品视 | 成人免费福利视频 | 亚洲高清在线观看 | 国产日韩一区二区三免费 | 在线免费看毛片 | 91精品国产91久久综合桃花 | av大全在线观看 | 91久久久久久久久 | 99免费在线观看 | 北条麻妃99精品青青久久主播 | 成人伊人| 国产精品视频 | 日韩视频在线播放 | 久久精品国产久精国产 | 国内精品久久久久 |