need EditText with readonly indent

2019-09-02 13:39发布

问题:

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:

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) {}
});