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

帶有不可編輯/不可取消后綴的 EditText

EditText with not-editable/not-cancellable suffix(帶有不可編輯/不可取消后綴的 EditText)
本文介紹了帶有不可編輯/不可取消后綴的 EditText的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號(hào)..

我為我的一個(gè)活動(dòng)創(chuàng)建了一個(gè)布局,用戶可以在其中在一些 EditText 小部件中插入一個(gè)值.我需要其中一些 EditText 必須具有不可編輯的后綴(如 cm、mm 等).用戶插入值后,我將解析這些 EditText 的內(nèi)容,避免使用后綴,因此我將處理唯一沒有后綴的輸入.該怎么做?

i created a layout for one of my activities in which users can insert a value in some EditText widget. I need that some of these EditText must have a suffix (like cm, mm and so on) that has to be not editable. After the user has inserted the value i will parse the content of these EditText avoiding the suffix so i will handle the only input without the suffix. How to do that?

我已經(jīng)在 SO 上進(jìn)行了搜索和搜索,但沒有任何幫助.我發(fā)現(xiàn)像這樣的答案 https://stackoverflow.com/a/20794581/2516399 對(duì)我沒有幫助.

I have already searched and searched here on SO but nothing helped me. I found answers like this one https://stackoverflow.com/a/20794581/2516399 that don't help me.

我希望我的問題很清楚......對(duì)不起我的英語

I hope i was clear in my question... sorry for my english

推薦答案

這是我的解決方案:一個(gè)在文本后面繪制后綴的 EditText 類.有兩個(gè)自定義屬性用于定義后綴的文本和后綴填充(到 EditText 的左角).

This is my solution: An EditText class that draws the suffix behind the text. There are two custom attributes for defining the text of the suffix and the suffix padding (to the left corner of the EditText).

public class EditTextWithSuffix extends EditText {
    TextPaint textPaint = new TextPaint();
    private String suffix = "";
    private float suffixPadding;

    public EditTextWithSuffix(Context context) {
        super(context);
    }

    public EditTextWithSuffix(Context context, AttributeSet attrs) {
        super(context, attrs);
        getAttributes(context, attrs, 0);
    }

    public EditTextWithSuffix(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        getAttributes(context, attrs, defStyleAttr);
    }

    @Override
    public void onDraw(Canvas c){
        super.onDraw(c);
        int suffixXPosition = (int) textPaint.measureText(getText().toString()) + getPaddingLeft();
        c.drawText(suffix, Math.max(suffixXPosition, suffixPadding), getBaseline(), textPaint);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        textPaint.setColor(getCurrentTextColor());
        textPaint.setTextSize(getTextSize());
        textPaint.setTextAlign(Paint.Align.LEFT);
    }

    private void getAttributes(Context context, AttributeSet attrs, int defStyleAttr) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.EditTextWithSuffix, defStyleAttr, 0);
        if(a != null) {
            suffix = a.getString(R.styleable.EditTextWithSuffix_suffix);
            if(suffix == null) {
                suffix = "";
            }
            suffixPadding = a.getDimension(R.styleable.EditTextWithSuffix_suffixPadding, 0);
        }
        a.recycle();
    }
}

這是屬性定義:

<resources>
    <declare-styleable name="EditTextWithSuffix">
        <attr name="suffix" format="string|reference" />
        <attr name="suffixPadding" format="dimension" />
    </declare-styleable>
</resources>

這篇關(guān)于帶有不可編輯/不可取消后綴的 EditText的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(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問題)
主站蜘蛛池模板: 国产91清纯白嫩初高中在线观看 | 国产精品一区二区在线免费观看 | 成人一区二区三区 | 538在线| 青青草国产在线视频 | avxxxxx| 成人黄色一级片 | 中文字幕一区在线观看 | 亚洲欧美视频在线观看 | 一区二区三区在线免费观看 | 成人免费激情视频 | 操欧美女人| 麻豆视频一区二区 | 97久久久久 | 天天干网站 | 日韩一区二区三区在线播放 | www亚洲天堂 | 亚洲精品视频在线播放 | 欧美亚洲三级 | 国产精品日韩在线 | 成人国产精品视频 | 日韩不卡在线观看 | 99精品网| 成人欧美一区二区三区黑人孕妇 | 日韩三级影院 | 手机看片在线 | 在线观看国产黄色 | 羞羞网站在线观看 | 久久小视频 | 玉足女爽爽91 | 午夜精品久久久久久久久久久久 | 国产网站免费 | 四虎免费在线观看 | 日韩欧美在线看 | 天天躁狠狠躁 | 青青草在线观看视频 | 激情播播网 | 亚洲福利视频一区 | www.久| 日韩黄色一级视频 | 性视频网 |