Android EditText帮助:EditText

时间:2015-10-31 08:13:58

标签: android android-layout android-edittext

我希望有一个edittext,旁边有一个不可编辑的文本(在左边,EditText的开头)。就像这个一样,我该怎么做呢?

EditText with a text beside it

2 个答案:

答案 0 :(得分:0)

Put constant text inside EditText which should be non-editable - Android

我发现这对那些想要它的人很有用。我还没有应用它,但这会起作用,对吧?

答案 1 :(得分:0)

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());

            }

        }
    });

试试这个......