need EditText with readonly indent

2019-09-02 13:34发布

Does anyone have ideas on how to achieve a blank indent on the first line of an EditText such that the user cannot modify the indent?

My goal is to superimpose some other info (possibly graphics) in the indent area and still allow the rest of the EditText to wrap long lines back to the normal left margin.

Fallback would be to add a separate line or column for the "other info", but that isn't as good a use of the screen real estate.

Perhaps there is better way to do this. Suggestions are welcome!

1条回答
我命由我不由天
2楼-- · 2019-09-02 14:05

I'm not sure on what are you trying to do but you can "modify" dinamically the text while is prompted.

Use a TextWatcher that offers you three method called in order. Try in debug with some breakpoints to understand better the variables and use them!

((EditText) findViewById(R.id.myEditText)).addTextChangedListener(new TextWatcher() {
      @Override
      public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

      @Override
      public void onTextChanged(CharSequence s, int start, int before, int count) {}

      @Override
      public void afterTextChanged(Editable s) {}
});
查看更多
登录 后发表回答