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

刪除 EditText 中的附加下劃線

remove additional underline in EditText(刪除 EditText 中的附加下劃線)
本文介紹了刪除 EditText 中的附加下劃線的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我有帶有自定義背景可繪制的 EditText:

I have EditText with custom background drawable:

編輯文本代碼:

<EditText
    android:id="@+id/etName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@{ViewModel.isAllowEdit  ? @drawable/profile_et_background_active : @drawable/profile_et_background}"
    android:inputType="@{ViewModel.isAllowEdit ? InputType.TYPE_CLASS_TEXT : InputType.TYPE_NULL}"
    android:text="@={ViewModel.name}"
    android:textColor="@color/main_dark_text_color" />

我正在使用 android 數據綁定庫和 MVVM 架構.

I'm using android databinding library and MVVM architecture.

如果 ViewModel 將 isAllowEdit 設置為 true,而不是將 EditText 背景設置為 @drawable/profile_et_background_active.

If ViewModel has isAllowEdit set to true than EditText background set to @drawable/profile_et_background_active.

如果 isAllowEdit false EditText 的背景設置為 @drawable/profile_et_background.

If isAllowEdit false EditText has background set to @drawable/profile_et_background.

另外我通過將 inputType 設置為 TYPE_NULL 來禁止編輯,并通過將 inputType 設置為 TYPE_CLASS_TEXT 來允許編輯.

Also i'm disallow edit by setting inputType to TYPE_NULL, and allow edit by setting inputType to TYPE_CLASS_TEXT.

@drawable/profile_et_background_active 代碼:

@drawable/profile_et_background_active code:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <shape android:shape="rectangle">
            <solid android:color="@android:color/transparent" />
        </shape>
    </item>

    <item
        android:left="-2dp"
        android:right="-2dp"
        android:top="-2dp">
        <shape>
            <solid android:color="@android:color/transparent" />
            <stroke
                android:width="1dp"
                android:color="@color/main_elements_line_color" />
        </shape>
    </item>

</layer-list>

@drawable/profile_et_background 代碼:

@drawable/profile_et_background code:

<item>
    <shape android:shape="rectangle">
        <solid android:color="@android:color/transparent" />
    </shape>
</item>

當允許編輯并且用戶開始在 EditText 中輸入文本時,輸入的單詞下方會出現額外的下劃線(它只屬于當前輸入的單詞,EditText 文本的所有其他部分都沒有下劃線):

When edit is allowed and user start typing text in EditText additional underline appears under typed word (it belongs only to currently typed word, all other parts of EditText text has no underline):

我試圖通過向 EditText 添加顏色過濾器來刪除該下劃線:

I tried to remove that underline by adding color filter to EditText:

et.setColorFilter(getResources().getColor(android.R.color.transparent), PorterDuff.Mode.SRC_IN)

但它不起作用.

如何去除多余的下劃線?

How can i remove that extra underline ?

更新 1

我已經嘗試添加@android:color/transparent,但出現錯誤:

I already tried to add @android:color/transparent, and I'm getting error:

java.lang.Integer 無法轉換為 android.graphics.drawable.Drawable"

"java.lang.Integer cannot be cast to android.graphics.drawable.Drawable"

當更改@{ViewModel.isAllowEdit ? @drawable/profile_et_background_active : @drawable/profile_et_background}"時

when changing "@{ViewModel.isAllowEdit ? @drawable/profile_et_background_active : @drawable/profile_et_background}"

到@{ViewModel.isAllowEdit ?@drawable/profile_et_background_active : @android:color/transparent}"

to "@{ViewModel.isAllowEdit ? @drawable/profile_et_background_active : @android:color/transparent}"

更新 2

添加 InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS 對我不起作用.所以我想這不是拼寫檢查的問題.

Adding InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS does not work for me. So i guess this is not Spell Checker's problem.

推薦答案

下劃線文本樣式由 EditTextBaseInputConnection 應用于當前正在合成"的文本;使用主題屬性 android:candidatesTextStyleSpans 應用的樣式,默認情況下設置為字符串 <u>candidates</u>.

The underline text styling is applied by the BaseInputConnection of EditText to the text currently being "composed" using the styling applied by the theme attribute android:candidatesTextStyleSpans, which by default is set to the string <u>candidates</u>.

字符串的文本部分被忽略,但樣式跨度從字符串中提取并應用于組合".text 是用戶當前正在輸入的單詞,a.o.表示可以選擇建議或自動更正處于活動狀態.

The text part of the string is ignored, but the style spans are extracted from the string and applied to "composing" text which is the word the user is currently typing, a.o. to indicate that suggestions can be selected or that autocorrect is active.

您可以更改樣式(例如,使用粗體或斜體代替下劃線),或完全刪除樣式,方法是將主題屬性設置為樣式化或非樣式化字符串:

You can change that styling (e.g. to use bold or italics instead of underlines), or remove the styling altogether, by setting the theme attribute to a styled or unstyled string:

<!-- remove styling from composing text-->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- ... -->
    <item name="android:candidatesTextStyleSpans">candidates</item>
</style>

<!-- apply bold + italic styling to composing text-->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- ... -->
    <item name="android:candidatesTextStyleSpans"><b><i>candidates</i></b></item>
</style>

警告:刪除所有樣式將導致 BaseInputConnection 實現在每次更改文本時重新評估主題屬性,因為跨度信息是延遲加載的,并且僅當屬性設置為樣式字符串時才會保留.您也可以設置 Html:fromHtml(...) 支持的任何其他樣式,例如<span style="color:#000000">...</span> 為默認的文本顏色,這在顯示上沒有區別.

Caveat: Removing all styling will cause the BaseInputConnection implementation to re-evaluate the theme attribute on every change of text, as the span information is lazy loaded and persisted only if the attribute is set to a styled string. You could alternatively set any other styling as is supported by Html:fromHtml(...), e.g. <span style="color:#000000">...</span> to the default text color, which makes no difference in display.

這篇關于刪除 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問題)
主站蜘蛛池模板: 欧美精品一区二区三区在线 | 久久国品片 | 午夜精品久久久久久久久久久久久 | 欧美高清性xxxxhdvideosex | 国产精品欧美一区二区三区不卡 | 可以在线观看av的网站 | 国产精品777一区二区 | 日韩视频免费在线 | 久久精品欧美一区二区三区不卡 | 国产婷婷在线视频 | 天堂精品| 亚洲综合一区二区三区 | 色资源在线 | 欧美综合一区 | 9久9久9久女女女九九九一九 | 欧美最猛性xxxxx亚洲精品 | 午夜免费观看体验区 | 中文字幕免费在线 | 一区二区三区国产在线观看 | 精品96久久久久久中文字幕无 | 亚洲一区二区三区在线观看免费 | 一区二区三区欧美在线观看 | 秋霞在线一区 | 色先锋影音 | 一级黄a| 中文字幕亚洲一区二区va在线 | 日韩三级一区 | 一区二区三区四区毛片 | 亚洲第1页 | 亚洲精品综合一区二区 | 日韩午夜在线播放 | 天天综合久久网 | 中文字幕亚洲一区 | 91久久精品日日躁夜夜躁欧美 | www.久草.com | 91中文字幕在线 | 亚洲视频免费在线观看 | 久久精品 | 久久777| 欧美一级欧美一级在线播放 | 国产a一区二区 |