简体   繁体   English

Android EditText 帮助:EditText 旁边的不可编辑文本

[英]Android EditText help: uneditable text beside EditText

I want to have an edittext that has an uneditable text beside it (on the left, the beginning of the EditText).我想要一个编辑文本,它旁边有一个不可编辑的文本(在左边,EditText 的开头)。 Just like this one, How do I go with this?就像这个一样,我该怎么办?

EditText 旁边有一个文本

Put constant text inside EditText which should be non-editable - Android 将不可编辑的常量文本放入 EditText 中 - Android

I found this useful for those who wanted it.我发现这对那些想要它的人很有用。 I haven't applied it yet but this would work, right?我还没有应用它,但这会起作用,对吧?

final EditText edt = (EditText) findViewById(R.id.editText1);

edt.setText("Speed");
Selection.setSelection(edt.getText(), edt.getText().length());


edt.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
            if(!s.toString().contains("http://")){
                edt.setText("http://");
                Selection.setSelection(edt.getText(), edt.getText().length());

            }

        }
    });

try this....尝试这个....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM