pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

刪除 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問題)
主站蜘蛛池模板: 罐体电伴热工程-消防管道电伴热带厂家-山东沃安电气 | 吸污车_吸粪车_抽粪车_电动三轮吸粪车_真空吸污车_高压清洗吸污车-远大汽车制造有限公司 | 深圳市宏康仪器科技有限公司-模拟高空低压试验箱-高温防爆试验箱-温控短路试验箱【官网】 | 纸张环压仪-纸张平滑度仪-杭州纸邦自动化技术有限公司 | 管家婆-管家婆软件-管家婆辉煌-管家婆进销存-管家婆工贸ERP | 余姚生活网_余姚论坛_余姚市综合门户网站 | 济南品牌设计-济南品牌策划-即合品牌策划设计-山东即合官网 | 校服厂家,英伦校服定做工厂,园服生产定制厂商-东莞市艾咪天使校服 | 台湾Apex减速机_APEX行星减速机_台湾精锐减速机厂家代理【现货】-杭州摩森机电 | 嘉兴恒升声级计-湖南衡仪声级计-杭州爱华多功能声级计-上海邦沃仪器设备有限公司 | 茅茅虫AI论文写作助手-免费AIGC论文查重_写毕业论文降重 | 铝箔-铝板-花纹铝板-铝型材-铝棒管-上海百亚金属材料有限公司 | 武汉不干胶印刷_标签设计印刷_不干胶标签印刷厂 - 武汉不干胶标签印刷厂家 | 真空泵维修保养,普发,阿尔卡特,荏原,卡西亚玛,莱宝,爱德华干式螺杆真空泵维修-东莞比其尔真空机电设备有限公司 | 镀锌钢格栅_热镀锌格栅板_钢格栅板_热镀锌钢格板-安平县昊泽丝网制品有限公司 | 手机存放柜,超市储物柜,电子储物柜,自动寄存柜,行李寄存柜,自动存包柜,条码存包柜-上海天琪实业有限公司 | 特种电缆厂家-硅橡胶耐高温电缆-耐低温补偿导线-安徽万邦特种电缆有限公司 | 韦伯电梯有限公司 | 卓能JOINTLEAN端子连接器厂家-专业提供PCB接线端子|轨道式端子|重载连接器|欧式连接器等电气连接产品和服务 | 广东高华家具-公寓床|学生宿舍双层铁床厂家【质保十年】 | 换网器_自动换网器_液压换网器--郑州海科熔体泵有限公司 | 消泡剂_水处理消泡剂_切削液消泡剂_涂料消泡剂_有机硅消泡剂_广州中万新材料生产厂家 | 比士亚-专业恒温恒湿酒窖,酒柜,雪茄柜的设计定制 | 悬浮拼装地板_篮球场木地板翻新_运动木地板价格-上海越禾运动地板厂家 | 进口便携式天平,外校_十万分之一分析天平,奥豪斯工业台秤,V2000防水秤-重庆珂偌德科技有限公司(www.crdkj.com) | HEYL硬度计量泵-荧光法在线溶解氧仪-净时测控技术(上海)有限公司 | 多物理场仿真软件_电磁仿真软件_EDA多物理场仿真软件 - 裕兴木兰 | 氢氧化钙设备_厂家-淄博工贸有限公司 | 滤芯,过滤器,滤油机,贺德克滤芯,精密滤芯_新乡市宇清流体净化技术有限公司 | 控显科技 - 工控一体机、工业显示器、工业平板电脑源头厂家 | 生态板-实木生态板-生态板厂家-源木原作生态板品牌-深圳市方舟木业有限公司 | 二手电脑回收_二手打印机回收_二手复印机回_硒鼓墨盒回收-广州益美二手电脑回收公司 | cnc精密加工_数控机械加工_非标平键定制生产厂家_扬州沃佳机械有限公司 | 电杆荷载挠度测试仪-电杆荷载位移-管桩测试仪-北京绿野创能机电设备有限公司 | 土壤养分检测仪|土壤水分|土壤紧实度测定仪|土壤墒情监测系统-土壤仪器网 | 中高频感应加热设备|高频淬火设备|超音频感应加热电源|不锈钢管光亮退火机|真空管烤消设备 - 郑州蓝硕工业炉设备有限公司 | 光泽度计_测量显微镜_苏州压力仪_苏州扭力板手维修-苏州日升精密仪器有限公司 | 美国HASKEL增压泵-伊莱科elettrotec流量开关-上海方未机械设备有限公司 | 餐饮小吃技术培训-火锅串串香培训「何小胖培训」_成都点石成金[官网] | 拉力机-万能试验机-材料拉伸试验机-电子拉力机-拉力试验机厂家-冲击试验机-苏州皖仪实验仪器有限公司 | 展厅设计公司,展厅公司,展厅设计,展厅施工,展厅装修,企业展厅,展馆设计公司-深圳广州展厅设计公司 |