EditText sometimes randomly not showing? - android

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"

Related

The last character of Button's text is partially visible

I have a FrameLayout which contains an EditText and a Button.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp">
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/edittext_hint"
android:inputType="textPassword"
android:maxLength="25" />
<Button
android:id="#+id/forgottenPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:background="#null"
android:fontFamily="#font/sf_pro_display_lightitalic"
android:padding="16dp"
android:marginRight="16dp" // still, it gets cropped
android:text="#string/password_button"
android:textSize="18sp" />
</FrameLayout>
I gave padding=16dp to the Button but somehow the question mark is partially visible. If I make the phrase short like "Forgot it?" then the '?' mark fully visible. I didn't understand. I gave it even marginRight=16dp, still...
But when I don't set fontFamily attribute, again it is fully visible.
The confusion I have is that how come the last character gets cropped even though it has padding and marginRight. I even tried adding space after the question mark but nothing changed. Am I missing something?
Edit: I am actually using strings.xml for the button's text. When I add space after the '?' in the strings.xml it doesn't effect the text in the button, however, when text is hard coded and added space after the '?', question mark is fully visible again. But as it is said over and over Hardcoded string is bad.
I can't make my phrase short like "Forgot it?", because the app is in Turkish and the original phrase is relatively long. And also I have to use that font.
That is because your font is italic. If you want to insert a space character in XML file use   after ? like this : ? .
That's because of the padding on your button. Remove the padding and try it out.
If all you want is some clickable text, there's no need for a Button:
<TextView
android:id="#+id/forgottenPassword"
android:clickable="true"
android:focusable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:fontFamily="#font/sf_pro_display_lightitalic"
android:padding="16dp"
android:marginRight="16dp"
android:text="#string/password_button"
android:textSize="18sp" />
Notice that I added clickable and focusable.

Android XML - EditText word-wrapping without newlines

I have this stupid and seemingly trivial problem with the properties of an EditText.
The properties I am trying to achieve for the EditText, are the following:
The contents of the view should NOT contain newlines. It can be text, numbers, symbols, but no newlines.
The soft keyboard should NOT display the enter button because of the above. It should instead display something like "Send" or "Done".
The contents of the view should NOT continue horizontally when reaching the edge of the screen. Instead I want to wrap the text, displaying it on multiple lines.
I have tried many different combinations, but I can not achieve this combination.
What I currently have is this, which is inside a RelativeLayout:
<EditText
android:id="#+id/comment_box"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_below="#id/preparation_text"
android:hint="#string/comment_hint"
android:inputType="textCapSentences|textAutoCorrect|text"
android:scrollHorizontally="false"
android:maxLength="400"
android:imeOptions="actionSend"/>
It achieves 2 of 3. No newlines possible, keyboard displays "Send" rather than the enter-key for me, but the text continues on one line.
Changing inputType="text" to "textMultiLine" wraps text correctly on multiple lines, but also overrides the keyboard to always display the enter button.
I have tried different solutions around the Internet, including setting the properties maxLines="4", singleLine="true" and possible others that I have forgotten again.
I can not find a combination that works.
Output:
Exp:
The op is on right track. I did some research found that some options gets ignored which are specified in XML. but if the same options are set in code then it should do the trick. I used the same XML fragment specified in the question.
<EditText
android:id="#+id/edit_text"
android:layout_width="match_parent"
android:layout_height="80dp"
android:hint="hint"
android:inputType="textCapSentences|textAutoCorrect|text"
android:scrollHorizontally="false"
android:maxLength="400"
android:imeOptions="actionSend"
/>
And by adding the following lines in the code, it helped in achieving what you want.
edit_text.setMaxLines(Integer.MAX_VALUE);
edit_text.setHorizontallyScrolling(false);
textShortMessage is the inputType that you are looking for:
<EditText
android:id="#+id/commentEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="100dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:gravity="left"
android:text=""
android:hint="hint"
android:textSize="16dp"
android:textColor="#android:color/black"
android:lineSpacingExtra="0dp"
android:lineSpacingMultiplier="1"
android:background="#android:color/white"
android:selectAllOnFocus="true"
android:inputType="textShortMessage|textMultiLine|textCapSentences"
android:singleLine="false" />
Refere to this to prevent paste function. To prevent pasting a new line.
Please use android:imeOptions="actionSend"
to solve your problem.
I have the same issue a long time ago, you have to programmatically change Edittext property on OnCreate().
So in XML, create your Edittext like this
<EditText
android:id="#+id/comment_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="80dp"
android:hint="Comment here"
android:maxLength="400"
android:inputType="textMultiLine" />
And on onCreate() (I wrote in kotlin not Java)
comment_box.imeOptions = EditorInfo.IME_ACTION_SEND
comment_box.setRawInputType(InputType.TYPE_CLASS_TEXT)

AutoCompleteTextview singleLine setText() with text longer than view size will cause broken words

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>

Android RelativeLayout editview how to make a text box bigger?

I'm trying to make a text box about 3 lines high but also the textbox will also expand depending on the amount of information entered. I've used wrap_content which displays as one line and I've used android:layout_height="150dp", however the text box does not expand. Any guidance would be much appreciated.
<EditText
android:id="#+id/editEmailCompose"
android:layout_width="400dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/editEmailSubject"
android:layout_toRightOf="#+id/textSubject"
android:ems="10"
android:gravity="top|left"
android:layout_marginRight="20dp"
android:hint="#string/emailCompose" />
Ok so I found the code required. It may help others.
*android:layout_height="wrap_content"
android:isScrollContainer="true"
android:minHeight="120dp"
android:inputType="textMultiLine"*

Dissapearing text when setting a TextView background in Android

Both properties are set programmatically. I tried restarting, changing AVD - bu still when TextView background is set - text dissapears. And yes, it has different color then background. Without background text is visible. I don't know where is the problem...
{This code below works fine}
<TextView
android:id="#+id/txt_Number"
android:layout_width="match_parent"
android:layout_height="25dp"
android:gravity="center"
android:text="1"
android:textColor="#color/red"
android:textSize="10sp"
android:textStyle="bold" />
This code below show only background, no text :/
<TextView
android:id="#+id/txt_Number"
android:layout_width="match_parent"
android:layout_height="25dp"
android:gravity="center"
android:text="1"
android:background="#drawable/txtbg"
android:textColor="#color/red"
android:textSize="10sp"
android:textStyle="bold" />
The image is in png format with transparent background. TextView is inside a TableRow in TableLayout. This Layout is part of the ListView item - but I don't think it's the problem.
With background:
Without background:
In fact, there are 2 TextViews, one showing distance and the second numbers - the first one has no background. When I try to put a background to the second one - both texts dissapear.
I faced with the same issue. After some researching I still don't know reasons to provide to this situation. To solve it, I simply put a View with desirable background below TextView. Not pretty but works.

Categories

Resources