Android Custom Edit Text Cursor Not Visible


I created a new simple project with a custom edit text without any logic (it just extends EditText). The code is the following:




The cursor is NOT visible if I use my custom edit text. It seems that its color is set as white (you can change the background and you will see that it is white).

Custom Edit Text - Cursor NOT visible
Custom Edit Text – Cursor NOT visible

But if I use EditText in the xml file, the cursor will be visible.

EditText - Cursor Visible
EditText – Cursor Visible

So it seems that the problem happens only for the custom edit text, even though it does nothing except for extending the EditText class(yes, I know, it’s a very weird behaviour :D, but that’s how it happens)


In the custom class, we have to extend AppCompatEditText instead of EditText.

And now, your Custom edit text should have a visible cursor 😀

Note: I did some tests and it seems that only starting Android 4 and above this strange behaviour happens. For Android 2.3.3 for example I could use a custom edit text which extends EditText class and it worked just fine.

Also, I want to mention that other people suggest to add the following attribute to the xml file where you declare the edit text:

It works, but if you use colors for your cursor, the color will not be changed. It will be always gray. So by extending AppCompatEditText you will keep your cursor’s style the same as the other cursors from your app.

[us_single_image image=”” align=”” img_size=”full” img_link_new_tab=”” animate=”” animate_delay=”” lightbox=”” link=””]

Android: How To Change Hint’s Size

If you need to set a smaller hint for your edit text, you can set the hint this way:

Also, you can set the size in the string resource file where is the string for the hint.

and in the xml file just set the hint as usual:


Android: Prevent cut-copy-paste popup to be displayed

If you ever need to disable the popup for cut-copy-paste when you long tap a text from an edit text you can do this by using the code below:

Android Stop Edit Text From Gaining Focus When Activity Starts

In this tutorial I will show you how to make the edit text not gaining focus when the activity starts. Sometimes this auto-focus can be annoying because the keyboard shows up even if we do not want to write something into our edit text. But let’s see what should be done in order to get rid of this issue.

1. Into your project files search for the AndroidManifest.xml file.
2. Open the manifest and put the following code between the activity tag:

And that’s all. Now the keyboard should not open automatically when your activity starts.

Android Hide Soft Keyboard and Show Soft Keyoard

In this tutorial I will present you how to hide the android soft keyboard and how to show it too. You might need to hide the keyboard, if, for example, you will have to put a limit of characters that can be introduced into the EditText and want to hide the keyboard when  the number of characters had reached the limit (exactly this scenario I will present you in this tutorial). And also, you might need to make the soft keyboard to pop-up when….hmmm….I don’t know when … but surely you will need it someday 🙂 In this tutorial we will make the soft keyboard to show up when a button is clicked. So let’s start!

1. Create a new project and call your java class(the one that is generated by Eclipse or other IDE)“MyActivity”.
2. Go to res – layout – main.xml and create an EditText and a Button like in the code below:

3. Go to MyActivity class and introduce the following code:

NOTE: The first method for showing the keyboard is working only if a physical keyboard is disabled. So if you test it on your emulator you have to disable the physical keyboard like in the pictures below. And the second method is working even if a physical keyboard is enabled or not.

First go where you can edit the emulator. In Intellij, go to Tools – Android – AVD Manager and select your emulator and press the Edit button. 

After the window with the Edit AVD is opened, click on the “New” button and select from the list “Keyboard support”. Now, that you selected the keyboard support, you must change it’s value from “yes” to “no”. And this is how you can disable the QWERTY support.

Android EditText text changes Listener

If you want “listen” to the text changes from an EditText you have to use the TextWatcher. Bellow I will show you an example of TextWatcher: