[TIMOB-13567] Android: Textfield cursor not visible when setting API level to 11 or above
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2014-07-29T23:31:14.000+0000 |
Affected Version/s | Release 3.0.0 |
Fix Version/s | 2013 Sprint 08 Core, 2013 Sprint 08 |
Components | Android |
Labels | n/a |
Reporter | Allen Yeung |
Assignee | Allen Yeung |
Created | 2013-04-15T21:32:04.000+0000 |
Updated | 2017-03-31T22:23:21.000+0000 |
Description
Steps to reproduce:
1. Add the following in your tiapp.xml:
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="14"/>
</manifest>
</android>
2. Use the following app.js:
Titanium.UI.setBackgroundColor('#000');
var win1 = Titanium.UI.createWindow({
title : 'Tab 1',
navBarHidden : true
});
var pw = Ti.UI.createTextField({
top : 20,
left : 10,
right : 10,
passwordMask : true,
backgroundColor : 'white'
});
win1.add(pw);
win1.open();
3. Click on the text field when the app is launched, and the cursor is white by default, which makes it nearly invisible.
NOTE: This is related to heavyweight windows. If you comment out navBarHidden, this bug does not appear.
The same problem exists with Ti.UI.Picker. If you substitute the TextField for a Picker, the default text is White with no way to change the color.
Another test case that seems to be related to this:
I am having a similar issue when I tap into the TextField it highlights for less than a second, then looses focus. Ti SDK 3.1.0.v20130409124549 Mac OSX for an Android App (Target Android SDK 2.3.3 & 3.0 both cause this issue)
[~underlabs] The code that you provided does not run. I had to change it to get it running:
Anyways, the focus issue is a known native android issue with list views. When using textfields inside a tableview, you should always set the windowSoftInputMode to Ti.UI.Android.SOFT_INPUT_ADJUST_PAN (Like I have done in the test case above. When the soft keyboard comes up, it causes the table view to resize, and lose focus. It does not regain focus correctly after this. The workaround is to use soft input adjust pan to prevent it from resizing.
For editText cursor not being visible see http://stackoverflow.com/questions/7238450/set-edittext-cursor-color
This is native android behavior where the cursor color is automatically set by the Holo theme. If you want to avoid this behavior, you would essentially need to adjust the theme. You can still use the holo theme and explicitly adjust the cursor color to match the text color by changing the theme. To do this, you need to set the 'android:textCursorDrawable' property (this property is only available on API 12 and above) to '@null'. To have your own custom theme, create a the theme.xml file under platform/android/res/values/theme.xml The theme.xml file would look something like:
NOTE: I still have a Theme.Titanium entry there since that is the default theme used for the main activity. If you leave this out, you will get a build error. Then in your tiapp.xml you will need to add the following entry to specify that your application will use the theme that you created:
This workaround will allow your app to have a cursor that inherits the color of your text. This will apply to all widgets in general if you plan on using the holo theme. For example, you may want to do something similar with the picker if there is an issue with that.
Marking as invalid. This is actually native android behavior, and developers should be using their own themes if they don't want the default holo theme. If they want the holo theme, the theme.xml should be changed as mentioned to modify the holo theme.
To hide title bar below
Hi. I found one issue with custom themes on Nexus 5 phone with Android 4.4.2 version. If text field's height is defined, text or cursor is not visible (actually, you can see one dot only). So, to see this issue, change original code:
and run code. Can this issue be reopened until some workaround is provided? Setting text field's height seems pretty common use case. Thanks!
I suspect you don't see a cursor because the font is bigger than the field's hight... Can you try setting the font size to 12 or 13 (14 will be too big)?
I tried that before but it didn't work. :(
i have the same issue. no workaround yet. That't painful because i wouldn't have the problem if i develop android native. so it could be an issue for TI.
[~ivanskugor] is there anything special about your custom theme? Just want to make sure we have all the steps to reproduce.
[~ingo], I am afraid Ivan will not reply, because his account has been migrated from lighthouse account and I had to fill my email in JIRA account. So I have got your question in email in result.
I got email :) Here is whole theme:
'20' for the height of a text field is too small to even see the text. If you change it to something like 100, the cursor shows up fine. Note that by default the cursor inherits the color from the theme, so I changed the color to 'black' so I could see the cursor better. I tried this on a Nexus 5 with 3.3.0.GA
Hello. Can you explain why this works on every Android phone that I have (like 10 pieces)? It even works on Nexus 7 tablet and Nexus 5 emulator. The only device on which this doesn't work is Nexus 5. Are all other devices buggy?! :D Sorry, but your workaround is just unacceptable, I can't change text field's height to 4 times bigger size - it will look ridiculous! Why fontSize doesn't work? Why can't I change it so text fits to 20px height? I'm testing with 3.2.2.GA because 3.3.0.GA is buggy! I'll get to that when I catch some time :) Ivan
Reopening issue.
After some investigation from Ivan (thanks for your help). It looks like the cause was related to
@Ivan Skugor Is there a workaround for this? I have AnyDensity=false in my TiApp.xml too. A first workaround for the cutted text is to set de height of the TextField to "Ti.UI.SIZE". But the cursor is not visibile with this fix. Do you have found any other way?
Hi. Unfortunately I haven't found a workaround except changing anyDensity setting. That shouldn't be too hard to change, just make sure you use "dip" (density independent pixels) as default unit in tiapp.xml. That should solve lots of issues, you just need to be careful if you use platformWidth/Height (you'll need to make your own calculation by dividing that value with "logicalDensityFactor"). Ivan
Hi there, We're getting the cursor to display on 3.3 using the following code:
Closing ticket as fixed, if there are any problems, please file a new ticket.