I have added this EditText field to my program. When I run this program, I have noticed that the cursor will blink very close to the left edge of the text box. I have many more text fields in the same layout. Because of the above mentioned problem, I cant see which text field is focused. So what is the solution?
Here is my code
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="#+id/lenbox"
android:textSize="20dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="120dp"
android:layout_marginTop="190dp"
android:background="#fb7567" />
You can try a different technique, I don't have an idea if that would be suitable for you or not.
What you can do is, add android:hint in the other EditText while your focus EditText will not show hint, hence giving an idea on where the focus is
Related
So I have an app that has this EditText. With some devices (generally the ones with higher resolutions), the EditText tends to randomly not show. However, it can be solved by restarting the app.
Here's a picture of how it should be:
And here's a picture of how it sometimes it randomly disappears:
It is important to clarify that the disappearing doesn't happen while the app is running, when you open the app, the editText is either there or not.
Thank you so much!
This is the XML for the EditText:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal|numberSigned"
android:ems="10"
android:id="#+id/abs"
android:editable="true"
android:numeric="decimal"
android:textAlignment="center"
android:textColor="#000000"
android:layout_centerVertical="true"
android:layout_alignLeft="#+id/btn"
android:layout_alignStart="#+id/btn"
android:layout_alignRight="#+id/btn"
android:layout_alignEnd="#+id/btn" />
android:layout_width="wrap_content"
The above line mean EditText will have same width as the size of text inside it. When EditText is empty it will be so small that you can't see.
You can fix this making EditText width same as its parent
android:layout_width="match_parent"
or you can fix width by providing your own width:
android:layout_width="80dp"
I have this EditText
<EditText
android:layout_width="match_parent"
android:layout_height="72dp"
android:hint="#string/write_message"
android:textColorHint="#color/primary_color"
android:ems="10"
android:imeOptions="actionDone"
android:inputType="textImeMultiLine"
android:id="#+id/message_input"
android:layout_gravity="center_horizontal"
android:backgroundTint="#color/primary_color"/>
When the box is filled up with user inputted text, it scrolls to the right to make room for more text, I do not like this behavior, and would prefer it if the EditText box expanded upwards when it needs more room? Is there a way to do this? Thanks.
Yes, this actually involves two things:
Making the EditText accept multi-line input.
Having its height grow as more text lines are added.
Therefore, to achieve this, you need to set up:
android:inputType="textMultiLine"
android:layout_height="wrap_content"
(Be mindful of the difference between textMultiLine and textImeMultiLine).
The full XML snippet would be:
<EditText
android:layout_width="match_parent"
android:inputType="textMultiLine"
android:layout_height="wrap_content"
android:hint="#string/write_message"
android:textColorHint="#color/primary_color"
android:ems="10"
android:imeOptions="actionDone"
android:id="#+id/message_input"
android:layout_gravity="center_horizontal"
android:backgroundTint="#color/primary_color"/>
Use both flags: textMultiLine will wrap your input, and textImeMultiLine will provide a break-line key in your keyboard.
<EditText
...
android:layout_height="wrap_content"
android:inputType="textImeMultiLine|textMultiLine"
... />
In my case I have multiline text, but it showed one line and a keyboard:
Though I have already set android:inputType="textCapSentences|textAutoCorrect|textMultiLine", it didn't help. Then I understood that when the keyboard appears in DialogFragment, it collapses the EditText. See DialogFragment and force to show keyboard to show keyboard when DialogFragment shows.
Then I added a short delay (100-300 ms) before showing the keyboard. Now I have:
In AndroidManifest I set android:windowSoftInputMode="adjustResize" for current activity.
I am doing my first android app and I hv a edittext area in which I need the cursor always show. Here "always show" means that even when a user tap the edittext for the first time, the cursor should show rather than it only gets showed after user really inputs something.
To make it clear, pls refers to the first picture and you can see when I tap the edittext area for the first time, only the softInputMethod shows but the edittext do not have a cursor:
And pls refers to the second picture and you can find that as long as I hv make ANY valid input, the cursor shows:
So is anyone who can tell me how to make the cursor ALWAYS SHOW even before I really make some valid inputs (to make the cursor show in the first picture)?
For your reference, I hv already tried to use android:cursorVisible="true" , android:focusable="true" and android:focusableInTouchMode="true" and even some other ways to achieve this. But none of it really fix this problem. So I really need some other suggestions.
Thanks a lot
P.S the below is my XML code for this edittext:
<EditText
android:id="#+id/typing_text"
android:background="#color/white"
android:hint="#string/typing_text_hint"
android:gravity="top"
android:textColorHint="#color/gray"
android:textColor="#color/black"
android:lines="6"
android:lineSpacingMultiplier="1"
android:digits="#string/digits"
android:imeOptions="actionDone"
android:inputType="textLongMessage|textMultiLine|textAutoCorrect|textCapSentences"
android:layout_marginBottom="7dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:longClickable="false"
android:cursorVisible="true"
android:maxLines="10"
android:scrollbarStyle="outsideInset"
android:scrollbars="vertical" />
As mentioned above, here's the actual line
android:textCursorDrawable="#null"
<EditText
android:textCursorDrawable="#null"
android:imeOptions="actionNext"
android:id="#+id/edSMobile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/edit_corner"
android:inputType="phone" />
I have the following AutoCompleteTextView :
<AutoCompleteTextView
android:id="#+id/contact_list_auto_complete_text_view"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:enabled="false"
android:hint=" Enter number"
android:singleLine="true"
android:textSize="20sp" >
</AutoCompleteTextView>
The input to this AutoCompleteTextView is done via a "Dialer" Layout I've created , thus this AutoCompleteTextView is android:enabled="false" and in order to add the user input on my AutoCompleteTextView I use the following code :
String mText =_searchAutoCompleteTextView.getText().toString()+_dialer_digits[position]; //the digit the user clicked upon
_searchAutoCompleteTextView.setText(mText);
_searchAutoCompleteTextView.performCompletion();
if(_searchAutoCompleteTextView.getText().toString().length()>2 && _searchAutoCompleteTextView.getAdapter().getCount()> 0)
{
_searchAutoCompleteTextView.showDropDown();
}
Every thing is working fine except a weird issue :
Since the input is not done by the device's keyboard and only by my dialer with setText() , if the user clicks alot of digits whihc are longer than the AutoCompleteTextView's size last digit is broken and while continuing to input more digits the AutoCompleteTextView does not scroll left. The weird thing about it is that I've tried to enable it and put some long input from the device's keyboard it works perfectly , long text is not broken and scrolling is happening. Since I cannot use the device's keyboard it must be done via my layout and setText()
Many thanks ahead
EDIT:
here is a screen shot :
You can use append instead of setText to move the cursor to the end.
I'm not sure if this will work but have you tried to put your AutoCompleteTextView in a HorizontalScrollView?
<HorizontalScrollView android:layout_width="wrap_content"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:id="#+id/contact_list_auto_complete_text_view"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:enabled="false"
android:hint=" Enter number"
android:singleLine="true"
android:textSize="20sp" >
</AutoCompleteTextView>
</HorizontalScrollView>
Can you provide a screen shot so I can better understand the issue you are having?
You need to set Gravity of AutocompleteTextVIew to right:
<AutoCompleteTextView
android:id="#+id/contact_list_auto_complete_text_view"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:enabled="false"
android:hint=" Enter number"
android:singleLine="true"
android:gravity="right"
android:textSize="20sp" >
</AutoCompleteTextView>
I have a EditText which I disabled the keyboard from popping up. And a set of buttons to enter text into the EditText with. The idea is to click a button -> enter some text into the text field.
I append the text to be input and the problem is that it just keeps appending on the same line. How can I get the text to go to a new line once we reached the end of the bounds of the text field (like how the default keyboard does)?
my edit text looks something like this:
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button1"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:inputType="textMultiLine"
android:scrollHorizontally="false"
android:gravity="top|left"
android:cursorVisible="true"
android:lines="10">
Ok I found what the problem is. I had disabled the softkeyboard by doing this:
Etext = (EditText) findViewById(R.id.editText1);
Etext.setInputType(0);
I found that when I didn't disable the softkeyboard, the multi line worked just fine.
Solution was to NOT setInputType(0) and set editable=false and inputType=none in the layout - now no keyboard shows and also text wraps to new line.
android:inputType="none"
android:editable="false"
//remove this
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"