0

je crée une application dans laquelle edittext ajoute durée de style à certaines positions de texteComment modifier automatiquement la position de l'étendue, si du texte a été ajouté avant le texte étendu dans EditText?

editable.setSpan(new StyleSpan(Typeface.BOLD), start, start+replacement.length(),Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 

Mon problème est que si ajoute l'utilisateur, un texte ou un espace blanc avant sera retiré le style de texte enjambée, comment éviter cela?

int SPAN_COMPOSING = 256; 
    int SPAN_EXCLUSIVE_EXCLUSIVE = 33; 
    int SPAN_EXCLUSIVE_INCLUSIVE = 34; 
    int SPAN_INCLUSIVE_EXCLUSIVE = 17; 
    int SPAN_INCLUSIVE_INCLUSIVE = 18; 
    int SPAN_INTERMEDIATE = 512; 
    int SPAN_MARK_MARK = 17; 
    int SPAN_MARK_POINT = 18; 
    int SPAN_PARAGRAPH = 51; 
    int SPAN_POINT_MARK = 33; 
    int SPAN_POINT_MARK_MASK = 51; 
    int SPAN_POINT_POINT = 34; 
    int SPAN_PRIORITY = 16711680; 
    int SPAN_PRIORITY_SHIFT = 16; 
    int SPAN_USER = -16777216; 
    int SPAN_USER_SHIFT = 24; 

De quel type aurai-je besoin dans mon cas?

+0

Utilisez TextWatcher. Vous recevrez un rappel pour chaque fois que votre texte a changé. utilisez setSpan ici. – Imdad

+0

pouvez-vous relire ma question? –

Répondre

-1

Vous pouvez utiliser comme ci-dessous le code.

editable.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) { 
       // here is your code to change position 
      } 

      @Override 
      public void afterTextChanged(Editable s) { 

      } 

     }); 
+0

pouvez-vous relire ma question? –

+0

pouvez-vous s'il vous plaît l'élaborer ou s'il est possible de m'envoyer avant après des images de celui-ci. –