java - EditText Not Visible in Emulator - Stack Overflow

admin2025-04-17  2

Screenshot attached

I'm new to Android Studio, and I am currently trying to create a simple event tracking app. The EditText for password is visible in the design view, but when running the app, is not present in the emulator. I have no idea what is going on...

I have tried changing the emulator, removed the cardview widget, switched from linear layout to relative layout... all unsuccessful. Bear with me. This is my first app, and I'm still learning how to use and manipulate all of the different components. Below is the code for the xml file.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=";
    xmlns:tools=";
    xmlns:card_view=";
    xmlns:app=";

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/custom_text"
    tools:context=".MainActivity">


   <androidx.cardview.widget.CardView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_margin="10dp"
      android:backgroundTint="#39423F3F">

    <ImageView
     android:id="@+id/imageView"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:src="@drawable/image" />

      <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_gravity="center_vertical"
         android:layout_marginTop="100dp"
         android:orientation="vertical"
         android:padding="24dp">

         <EditText
            android:id="@+id/username"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginTop="0dp"
            android:background="@drawable/custom_text"
            android:drawablePadding="8dp"
            android:hint=" Username"
            android:outlineAmbientShadowColor="#A25252"
            android:textColor="@color/black"
            android:textColorHighlight="@color/cardview_dark_background" />

            <EditText
              android:id="@+id/user_password"
              android:layout_width="match_parent"
              android:layout_height="50dp"
              android:layout_marginTop="15dp"
              android:background="@drawable/custom_text"
              android:drawablePadding="8dp"
              android:hint=" Password"
              android:textColor="@color/black"
              android:textColorHighlight="@color/cardview_dark_background" />

           <Button
              android:id="@+id/loginButton"
              android:layout_width="200dp"
              android:layout_height="60dp"
              android:layout_marginLeft="60dp"
              android:layout_marginTop="30dp"
              android:backgroundTint="@color/black"
              android:clickable="true"
              android:text="Login"
              android:textColor="@color/white"
              android:textSize="18sp" />

            <Button
              android:id="@+id/signUpButton"
              android:layout_width="200dp"
              android:layout_height="60dp"
              android:layout_marginLeft="60dp"
              android:layout_marginTop="8dp"
              android:backgroundTint="@color/black"
              android:clickable="true"
              android:enabled="true"
              android:text="Sign Up"
              android:textColor="@color/white"
              android:textSize="18sp" />


        </LinearLayout>
    </androidx.cardview.widget.CardView>
</LinearLayout>

Screenshot attached

I'm new to Android Studio, and I am currently trying to create a simple event tracking app. The EditText for password is visible in the design view, but when running the app, is not present in the emulator. I have no idea what is going on...

I have tried changing the emulator, removed the cardview widget, switched from linear layout to relative layout... all unsuccessful. Bear with me. This is my first app, and I'm still learning how to use and manipulate all of the different components. Below is the code for the xml file.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/apk/res-auto"

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/custom_text"
    tools:context=".MainActivity">


   <androidx.cardview.widget.CardView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_margin="10dp"
      android:backgroundTint="#39423F3F">

    <ImageView
     android:id="@+id/imageView"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:src="@drawable/image" />

      <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_gravity="center_vertical"
         android:layout_marginTop="100dp"
         android:orientation="vertical"
         android:padding="24dp">

         <EditText
            android:id="@+id/username"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginTop="0dp"
            android:background="@drawable/custom_text"
            android:drawablePadding="8dp"
            android:hint=" Username"
            android:outlineAmbientShadowColor="#A25252"
            android:textColor="@color/black"
            android:textColorHighlight="@color/cardview_dark_background" />

            <EditText
              android:id="@+id/user_password"
              android:layout_width="match_parent"
              android:layout_height="50dp"
              android:layout_marginTop="15dp"
              android:background="@drawable/custom_text"
              android:drawablePadding="8dp"
              android:hint=" Password"
              android:textColor="@color/black"
              android:textColorHighlight="@color/cardview_dark_background" />

           <Button
              android:id="@+id/loginButton"
              android:layout_width="200dp"
              android:layout_height="60dp"
              android:layout_marginLeft="60dp"
              android:layout_marginTop="30dp"
              android:backgroundTint="@color/black"
              android:clickable="true"
              android:text="Login"
              android:textColor="@color/white"
              android:textSize="18sp" />

            <Button
              android:id="@+id/signUpButton"
              android:layout_width="200dp"
              android:layout_height="60dp"
              android:layout_marginLeft="60dp"
              android:layout_marginTop="8dp"
              android:backgroundTint="@color/black"
              android:clickable="true"
              android:enabled="true"
              android:text="Sign Up"
              android:textColor="@color/white"
              android:textSize="18sp" />


        </LinearLayout>
    </androidx.cardview.widget.CardView>
</LinearLayout>
Share Improve this question edited Feb 1 at 6:16 SO8787 asked Feb 1 at 6:12 SO8787SO8787 11 bronze badge 1
  • I have edittext displayed for password entry, maybe you programmatically changed the visibility somewhere. – dmortal Commented Feb 1 at 6:27
Add a comment  | 

1 Answer 1

Reset to default 0
  1. Your card view contains multiple child elements without containing viewGroup(Relative or constraint layout) in the cardview first you take one view group and inside place all whatever you want.

  2. It maybe because of your android:background="@drawable/custom_text" check it this properly it once what it is doing.

  3. Remove backgroundTint for the card it maybe confict with the cardview

  4. And try to apply the visiblity for the edittext at run time edittext.setVisibility(View.VISIBLE);

let me know still if you face any issue

转载请注明原文地址:http://anycun.com/QandA/1744837070a88307.html