One of the users of my app is having an issue where the text he enters in the EditText elements of my app is white, which effectively renders it invisible against a white background. He's the only user experiencing this issue, and it's only happening to him in my app.
As an example, here's the code for one of my EditText elements:
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/usernameTextBox"
android:imeOptions="actionDone"
android:singleLine="true"/>
There are dozens of these in my app, and all are essentially coded the same. Any ideas why this might be happening?
Every android distribution can overwrite default colors for widget. Therefore, if you want all of your EditText to look the same you should explicitly set their background and text color like so:
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/usernameTextBox"
android:imeOptions="actionDone"
android:singleLine="true"
android:background="#FFFFFF"
android:textColor="#000000"/>
To ensure that the text colour being displayed correctly, strictly set the textColor attribute for each declared TextView like so android:textColor="#android:color/black"
Related
I'm trying to make an app like the one in this mockup:
Supermarket
It's a very simple supermarket app. As you can see, there's a TextView at the bottom of the screen that tells me whether my Cart is empty, or has items in it. If the cart is not empty, the user is shown the total price he/she must pay. You can also notice that said TextView's style and text change according to a variable (in this case, "totalPrice").
How can I do this in Android? I know I can use simple if statements (if totalPrice == 0, then backgroundColor = grey and text = "EmptyCart", for example), but this seems somewhat... hardcoded. Is there a better way to do it? As you can see, the TextView's style and values also change when on the "Subproducts" activity (some Products have Subproducts, which you can see after clicking on them).
Thanks in advance!
I think Databinding is the best way rather than boilerplate code.
create a model class and change background of the view using ternary operation in databinding also manage visibility of price text using this.
To set a textview's text, you use textView.setText("new text"); To set its background, its textView.setBackgroundColor(color) where the color is the hexcode you want as an integer- for example 0xFFFF0000 for reg. Obviously these can be variables as well as hard coded.
It can simply be achieved with two TextViews in a RelativeLayout, and of course, by using basic TextView's methods. As an example layout:
<RelativeLayout
android:layout_height="75dp"
android:layout_width="match_parent"
android:background="#1EC4F3">
<TextView
android:text="PAY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:typeface="sans"
android:textColor="#FFFFFF"
android:textSize="18sp"/>
<TextView
android:layout_height="wrap_content"
android:text="$25.79"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="8dp"
android:typeface="monospace"
android:textSize="14sp"
android:textColor="#FFFFFF"/>
</RelativeLayout>
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.
EditText is disabled, but still it is underlined. Why, how can I remove underline? What exactly underline means? In iOS same component is UITextView but it never underline so the control.
<EditText
android:layout_width="305dp"
android:layout_height="79dp"
android:inputType="textMultiLine"
android:ems="10"
android:layout_below="#+id/view"
android:layout_centerHorizontal="true"
android:layout_marginTop="0dp"
android:id="#+id/editText5"
android:text="Do you know y.."
android:enabled="false" />
EditText is disabled
Use a TextView instead.
how can I remove underline?
Use a TextView instead.
Or, use a different background for the EditText, probably. I assume that the Theme.Material/Theme.AppCompat way of supplying that bracket is via the background, as it was with Theme and Theme.Holo. I have not changed the background of an EditText in years, as usually it is not needed.
What exactly underline means?
It tells humans that this represents text that they can edit, as opposed to text that they cannot edit.
while typing into EditText, text color automatically changing from black to white, initially i set the text color to white and set hint color also white, but when testing it, it shows typing in black color on start but while in mid or reach to a random number of characters, it turns to white text. its working fine Samsung Galaxy Gio, Nexus One and on different emulators but on HTC Evo 3G and some other devices, its showing this behavior!
I tried to fix by setting style to normal, text color to white, hint color to white and other things relating to focus etc, everything is set to white but still on some devices it is showing the behavior and continues to changing color in mid of typing.
Please let me know if someone is familiar with this and fixed any issue like this.
Here is the video demonstrating the issue.
http://youtu.be/1dydBvZnSHI
Here is my xml for this EditText
<EditText
android:id="#+id/email_edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/textView2"
android:background="#drawable/share_email_bg"
android:ems="10"
android:lines="1"
android:maxLines="1"
android:padding="5dip"
android:singleLine="true"
android:textColor="#ffffff"
android:textColorHint="#ffffff"
android:inputType="textEmailAddress"/>
Well I am answering this because some may get benefit out of this. Actually I got the same problem in one of my device and after a long struggle I found that its a very silly mistake.
To solve this we just need to add one attribute in the <EditText> node. Here is the solution :
<EditText
android:textColor="#android:color/black"
..........
/>
Use:
android:textColorHighlight="#android:color/black"
in the textEdit if you refer to edit text down line change color when editing you need to set the color on:
android:backgroundTint="#color/colorPrimaryDark"
hi i want to create a control for my activty which is just like an android default dialpad number showing control. i created edittext control for it.
<EditText android:id="#+id/editid"
android:hint="Enter your number"
android:layout_width="fill_parent"
android:scaleType="center"
android:singleLine="true"
android:cursorVisible = "false"
android:layout_height="wrap_content"
>
</EditText>
But its not looking great as i am trying to show the inpput number from centre and keep on decreasing its text size if there are more numbers entered upto a certain size.Also i am unable to set its background drawable to make it look like dialpad's input box.
i also tried with button control.
<Button android:layout_height="45dp"
android:textSize = "25dp"
android:singleLine = "true"
android:id="#+id/input_number"
android:textColor = "#color/white"
android:layout_width="320dp"
android:background="#drawable/num_button">
</Button>
its showing exactly as i want but the problem is now i am not been able to set its text from qwerty keypad as edit text was taking it automatically.
Please someone suggest me which control to choose and get the desired behaviour.
Thanks
Set the gravity of Editext as center and it will work
android:gravity="center"