Enfin, je fonde la solution. J'ai résolu ce problème via InputType. C'est mauvais, mais rien de mieux que je n'ai pas trouvé. Dans CustomEditText vous devez remplacer la méthode OnSelectionChanged et changer InputType il:
public boolean isWasCap = false;// Was capitalisation turn on?
public void onSelectionChanged(int selStart, int selEnd) {
...
setCap();
}
/**
* Method check is need turn on capitalization
*/
private void setCap(){
int start = getSelectionStart();
int end = getSelectionEnd();
if (start == end && start > 0
&& getText().charAt(start-1) == INVISIBLE_SYMBOL) {
if(isWasCap) // Capitalization is turn on
return;
setInputMask(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES, InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);
isWasCap = true;
}else if(isWasCap){
isWasCap = false;
setInputMask(InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS, InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
}
}
/**
* Method replace one input type to other input type
* @param needRemove - mask which will remove
* @param needSetup - masr which will setup
*/
public void setInputMask(int needRemove, int needSetup){
int mask = getInputType() & ~needRemove;
mask = mask | needSetup;
setInputType(mask);
}
style.xml
<style name="Common.Editor">
<item name="android:inputType">textCapSentences|textMultiLine|textAutoCorrect</item>
</style>
main_activity.xml
<com.view.CustomEditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Common.Editor"
/>
texte 'Edit a créé avec symbol' invisible ce qu'il vouloir dire par? –
Je pense qu'il initialise # à la première lettre. pourquoi ne peux-tu pas ajouter # dynamiquement quand tu prends la valeur en java side ?? – Jithu
shylendra, EditText mEditText = (EditText) findViewById (...); mEditText.setText ('#'); Et l'utilisateur peut entrer seulement après ce symbole. Jithu, Parce que # est le nouveau symbole du nouveau paragraphe. Il faut corriger applySpans Paragraphe – Dima