I have an EditText
and a Send Button
in a layout:
<RelativeLayout
android:id="@+id/messageLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<Button
android:id="@+id/sendButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send"
android:textColor="@color/blue"
android:background="@drawable/send_button"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_alignParentRight="true"
android:textAllCaps="true"
android:enabled="false"
/>
<EditText
android:id="@+id/messageEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="4"
android:maxLength="500"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@id/sendButton"
android:background="@drawable/edittext"
android:textColor="@color/black"
android:inputType="textCapSentences|textMultiLine"
/>
</RelativeLayout>
The purpose is to type in the EditText
and then press Send to send the message.
I tried this in 4 different phones:
In all of them the keyboard shows up to type. In 3 of them (Smasung Galaxy S3, Samsung Galaxy S4, and Lenovo A820) I can type and see the text entered to the EditText
(and send successfully, but that's irrelevant now).
In the 4th phone (Meizu MX5), I can't see what I'm typing (the background is white and the text is black - so that's not the problem). It doesn't even get to my onTextChanged
listener with this phone.
Why is this happening and how can I solve it?
Here's the listener:
messageEditText.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) {
if (!s.toString().isEmpty() && !send.isEnabled()) {
send.setEnabled(true);
send.setTextColor(getResources().getColor(R.color.blue));
} else if (s.toString().isEmpty() && send.isEnabled()) {
send.setEnabled(false);
send.setTextColor(getResources().getColor(R.color.gray));
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
Edit:
Edit2:
OK this is really strange. Please check out the video:
http://vid90.photobucket.com/albums/k274/alaa_137/sendmessage_zpsqzar2fda.mp4
In the first 2 seconds, I'm typing, and nothing appears.
Then I long press the backspace button, "deleting" all what i had written.
Then I click one of the messages above (these are received messages).
The keyboard goes down (good).
I click the keyboard, and it goes up (good).
I start typing again, and I see Chinese characters! Also, the Send button doesn't become blue, which means it doesn't recognize any text in the EditText
.
[This only happens in the Meizu]
Edit3:
The problem is in inputType textMultiLine
. If I write android:inputType="textCapSentences"
instead, everything works fine. But I do want the textMultiLine
. So what can I do?
Problem solved.
Change inputType
in xml to:
android:inputType="textCapSentences"
And add to code after assigning the EditText
instance:
messageEditText.setSingleLine(false);
messageEditText.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
I don't know why, but it works.