Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7895217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:35:22+00:00 2026-06-03T07:35:22+00:00

I have two EditTexts for a username and password, each having the text ENTER

  • 0

I have two EditTexts for a username and password, each having the text “ENTER A USERNAME” and “ENTER A PASSWORD” respectively, as their default text.

Their text colors are a light gray. Now when they get focused they’re supposed to change text colors as well as the password edittext’s inputType to a password type (on top of other things but that works).

It successfully changes the text color to black at first but fails to change back and the inputType never changes.

Please suggest me where I am lacking, below is my code:

OnFocusChangeListener pwListener = new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if(hasFocus) {
                //if it has focus then clear the text and make text black
                if(((EditText) v).getText().toString().compareTo(getString(R.string.passwordField)) == 0) {
                    ((EditText) v).setTextColor(R.color.Black);
                    ((EditText) v).setText(R.string.blank);
                    ((EditText) v).setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
                }
            } else if(!hasFocus) {
                //if it loses focus and nothing was inputed then change back to default
                if(isEmpty(((EditText) v).getText().toString())) {
                    ((EditText) v).setTextColor(R.color.TextInput);
                    ((EditText) v).setText(R.string.passwordField);
                    ((EditText) v).setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME);
                }
            }
        }
    };

Thats the passwords edit text and this is its XML:

<EditText
    android:id="@+id/passwordInput"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inputType="textPersonName"
    android:layout_marginTop="5dip"
    android:layout_marginLeft="20dip"
    android:layout_marginRight="20dip"
    android:paddingTop="15dip"
    android:paddingBottom="15dip"
    android:text="@string/passwordField"
    android:textColor="@color/TextInput"
    android:textSize="25sp"
    android:gravity="center_vertical"
    android:ems="10" >
 </EditText>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:35:24+00:00Added an answer on June 3, 2026 at 7:35 am

    Why you dont set the ENTER A USERNAME” and “ENTER A PASSWORD” as hint text in Edittext using

    android:hint="Enter User Name"
    

    It will automatically disappear when user clicked on Edittext.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple login Activity having two edit texts fileds, for username and
I have two EditTexts in XML. In one EditText, the user can put a
I have an activity with style Dialog, containing two EditTexts. However, only the first
I have two classes that extend the activity class. Each class has it's own
I have a login screen with two EditTexts and a login button in my
This is my code. So when button is clicked, I have two edit text
I have an activity with two EditTexts. If, in landscape mode, I select the
I have and android layout with two edittexts one for Qty and one for
I have two textbox and a checkmebox. But when i type my username and
I have a single activity class and it has a two EditTexts on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.