EditText cursor is invisible in Android 4.0 - android

I have an EditText input in Android 4.0 and the Cursor is not showing inside it.
What can make the cursor not appear in the input field?

Make android:cursorVisible="true"
and
If you have used android:textColor then set the android:textCursorDrawable attribute to #null.
Happy coding ;)

I had a similar problem but it was because the cursor is actually white and I had a white background. I needed to be able to change the cursor to black in code somehow and used this approach.
I created a layout resource called textbox.axml which contained this
<?xml version="1.0" encoding="utf-8"?>
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="This is a template"
android:background="#ffffff"
android:textColor="#000000"
android:cursorVisible="true"
android:textCursorDrawable="#null" />
I then applied this layout in code (C# because I am using Xamarin) thus
EditText txtCompletionDate = (EditText)LayoutInflater.Inflate(Resource.Layout.textbox, null);
but it is similar in Java.

Add this line for your edit text in the xml file.
android:textCursorDrawable="#null"

I happened quite same problem - cursor was showing up only after user types some characters. I tried solutions listed here, but without any success on my device. What actually work for me, is setting blank text to my edittext:
EditText editText = findViewById(R.id.edit_text);
editText.setText("");
This "fakes" the user input, and cursor appears.

My issue was that I was using the AppCompat theme, but I had some custom view classes that extended EditText that needed to extend AppCompatEditText in order for the AppCompat style to be applied correctly.

Add this line for your edit text in the xml file.
android:cursorVisible="true"

Just adding my own personal fix to anyone it might help. I had tried everything here but forcing android:background="#null" was causing a very tiny cursor only at the end of my right aligned TextEdit (it was right working fine elsewhere).
Simply adding android:padding="1dp" in my TextEdit solved the issue.

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 found what was causing it to happen to me.
You need to inherit it from the application's theme. I'm not sure what the line item needs to be exactly, but android:Theme has it so inheriting that will do that trick.
Using the default AppBaseTheme will work (it has android:Theme.Light as it's parent).
To use AppBaseTheme put android:theme="#style/AppBaseTheme" into your application tag in the manifest. You can also use a custom style and multiple levels of inheritance so long as one of them has parent="android:Theme" in the style tag.Like I said it may be possible to have it without that, just using certain line item(s) but I don't know what those would be.
If you don't need a custom theme you can just use
android:theme="#android:style/Theme"

In My case the cursor is visible if user language is English but if he change his language to Arabic then its not visible.
To fix this I have created on custom drawable for cursor.
Cursur shap at drawable/black_cursor.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#a8a8a8"/><!-- This is the exact color of android edit text Hint -->
<size android:width="1dp" />
</shape>
Edit Text:
<EditText
android:id="#+id/user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textCursorDrawable="#drawable/black_cursor"
/>

If the EditText has a Background drawable with a border, the cursor is displaying in the border and appears to be invisible. To rectify the problem set padding in the EditText to a small amount e.g. 5dp

If you want to show the cursor then just do
android:textCursorDrawable="#null".

Related

How to add a spacing between text and underline in android?

I have defined text of a textview as -
<string name="text"><u>this is my text</u></string>
I needed some space between the text and the underline, so I added lineSpacingExtra="2dp" to the textview, but it is not working.
Can anyone tell how to achieve this?
I need to support API 14 till 21. The above test was done on API 21.
I spent a great deal of my time on this question and here are my findings!
Firstly, To increase the spacing between the text and underline in css you need to use styles and unfortunately Android TextView does not support style tag when using Html.fromHtml(). Unfortunately even span tag is not supported (otherwise that could have been used). To see the entire list of tags supported check the HTML Tags Supported By TextView blog.
Now since we know the basic simple implementation wouldn't work, the only other way remaining is to fake it (fool the user!). In your xml layout where you have the TextView add a View below it with the following properties.
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/text"
android:textSize="20sp"/>
<View
android:id="#+id/underlineView"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignEnd="#+id/textView"
android:layout_alignLeft="#+id/textView"
android:layout_alignRight="#+id/textView"
android:layout_alignStart="#+id/textView"
android:layout_below="#+id/textView"
android:layout_marginTop="10dp"
android:background="#android:color/holo_red_dark"/>
As you can see the underlineView is emulating the underline. It has its width fixed to the textview above it. You can set its color to whatever you need and importantly you can adjust the spacing using the android:layout_marginTop property. Hope this helps!
My suggestion is to remove the underline from the text string entirely because you can't customize the spacing from there. After that, you have a few options. One option is to use the #drawable feature as discussed in the following link: http://www.quora.com/How-do-I-design-edit-text-view-with-bottom-border-alone-in-Android-and-edit-text-view-with-some-special-symbol-like-below-image
If you want a quick and easy "hack" then go to the layout XML for your activity where your TextView is created. Wrap your TextView in a LinearLayout as follows:
<LinearLayout
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/text"
android:layout_marginBottom="2dp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#color/underline" />
</LinearLayout>
The first TextView is where your text ("this is my text") is displayed so you can adjust the "layout_marginBottom" to whatever spacing you need between your text and the underline. The second TextView acts as your underline so to adjust its thickness you can change the "layout_height" value.
The final step to making this work is to go into your "values" folder in your project and create a new XML file named "colors.xml". The entire contents for this example are below:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="underline">#333333</color>
</resources>
Simply change the hex color value in this XML file to customize the underline color to your choice.

Styling an Android edit text so as to look like a drop down / spinner picker

I have two EditText views on a layout containing a date and a time. On being clicked these open up my custom DatePickerFragment and a TimePickerFragments. I would like to style the EditTexts with a picker drop corner as the following image shows.
however I have not been able to do this, my text fields look like this:
The pickers all work and are hooked up and return values to the EditTexts, I just want to do the styling correctly. I am happy to change the class of the containers from EditText if they should be something else to get the desired behaviour. I think this should be possible as the first image comes from Google's own design documentation. Looking through the EditText and TextView class documentation and xml attibute documentation. Is there a way to do this?
I am using Xamarin to compile this down but that should make no difference to the answer.
set the Style attribute to the following:
<EditText
style="?android:attr/spinnerStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
use following image as background of your edittext
make it 9 patch with whatever colour you want.
find an original image and Create a nine patch image like below..
Note : Black Lines are patches
And then add image to background of EditText like below..
<EditText
android:id="#+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/box_edittext"
android:padding="10dp" />
OR
You can use this simple way...
Define style="?android:attr/spinnerStyle" to EditText..
<EditText
style="?android:attr/spinnerStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>

What is the small graphic displayed under an EditText called and how can I remove it?

After some pretty thorough googling I still cannot figure out what the the little graphic that's displayed under the text in and EditText View is called. I would also like to remove it either using XML or programmatically. The little graphic is the thing under the cursor in this image: http://1.bp.blogspot.com/-UAuOq0h4Vok/T8reinvaWPI/AAAAAAAABPc/N4yibXd3kZg/s1600/android%2Bedittext%2Btext%2Bchange%2Blistener%2Bexample.jpg . Sorry if this is a dumb question, but without the name of this little graphic feature I can't seem to find out anything about it.
It is the background drawable associated with the edittext. You can change it by manually setting the background to something yourself, such as
<EditText
android:background="#android:color/transparent"
...
/>
Try this..
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/hello"
android:background="#00000000"
/>
if you want transparancy just put 80 before the actual hash code.
#80000000
This will change any colour you want to transparent one.. :)
you probably have in your layout
android:minLines="2"
try to remove it

Android 4.3+, android:textColorHint doesn't work, hint color is always white

As the question says: When testing the app on devices running Android 4.3+ (also tested on 4.4), the color of the hints (for EditText) turns white, and no matter what color I set it to, it remains white. Since the EditText's background is white, the hints isn't visible to the naked eye!
I've googled and googled and can't find anyone having the same issue. The app was built using android:minSdkVersion="8" and android:targetSdkVersion="15". The EditText looks like this:
<EditText
android:id="#+id/editText3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/my_background"
android:ems="10"
android:textColorHint="#color/BlueViolet"
android:hint="#string/my_hint"
android:inputType="number"
android:tag="21_0" />
At first it was using the default android:textColorHint and I thought that maybe Android 4.3+ changed the default to white for some reason. But that doesn't seem to be the case since whatever color I set it to, it's always white.
I'm aware that fill_parent is deprecated, but the app was build quite some time ago, but is now unuseable due to hints disappearing. Any help is appreciated! Thanks!
EDIT:
The 'error' seem to occur when using a String-resource for hint. This works: android:hint="Hello world" while this doesn't android:hint="#string/my_hint"
For who struggles with same problem;
If you used your edittext in
android.support.design.widget.TextInputLayout
you should put your
android:textColorHint="#color/BlueViolet"
in TextInputLayout
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColorHint="#android:color/white">
<AutoCompleteTextView
android:id="#id/etextEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_card"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true"
android:textColor="#android:color/white"/>
</android.support.design.widget.TextInputLayout>
It seems since Android 4.3+ it's no longer possible to make String-resources as follows (not sure if it was ever meant to work this way though):
<string name="my_hint"><font size="13" fgcolor="#ffbbbbbb">Hello world</font></string>
If you do, they turn out white. So you are stuck with creating the String-resource this way:
<string name="my_hint">Hello world</string>
And then use the properties on the TextView/EditText to edit the color of the hint. To change the size, it seems it's still possible to do:
<string name="my_hint"><small><small>Hello world</small></small></string>
I found this out by reading the comment of this answer: https://stackoverflow.com/a/11577658/2422321, by Edward Falk
In addition to Erhan's answer or incase you are using the TextInputLayout widget,
I found that using app:hintTextColor instead of android:textColorHint works best

How to Remove Request Focus from EditText?

I want to remove the blue line from edittext when i touched edittext it appear but i dont know how to remove it. see the picture for more understanding
do it this way
lUserNameEditText.clearFocus();
another way which works for me regarding the border is
lUserNameEditText.setBackgroundColor(0);
Have you tried changing the Layout XML like this
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:background="#00000000"
/>
or do it via code
editTextView.setBackgroundColor(0);
remove requestFocus tag in xml layout so automatically focus will loss

Categories

Resources