1

I have started learning Android Studio and Kotlin, and I am making an application. Previously, I was having a problem where an activity was not loading. The problem was fixed by cleaning the code and restarting the application. But now, as I put an editText in the activity, there are very few properties shown for the editText and many are absent (for example- gravity, textColor and hint).

here's a screenshot

here's the XML:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/VSAC_page_heading"
        android:layout_width="376dp"
        android:layout_height="83dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="24dp"
        android:layout_marginEnd="16dp"
        android:gravity="center"
        android:text="Volume and Surface Area of Cubes and Cuboids"
        android:textColor="#673AB7"
        android:textSize="26sp"
        android:textStyle="bold|italic"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="Name"
        tools:layout_editor_absoluteX="113dp"
        tools:layout_editor_absoluteY="150dp" />

</androidx.constraintlayout.widget.ConstraintLayout>

3 Answers3

0

Restart Android studio or rebuild the project and and update your gradle it may solve your problem. This kind of problem sometimes occurs due to file synchronization problems.

Md shah samir
  • 85
  • 1
  • 5
0

Try clean and rebuild the project, if again you have that problem try file -> invalidate caches/restart

MMG
  • 3,226
  • 5
  • 16
  • 43
0

I have changed some parts of your XML and the EditText displays correctly the color, the hint and gravity (in the XML you attach the EditText has no gravity, textColor or hint parameters).

Maybe you were using "tools" namespace in these parameters instead of "android". Note that using "tools" namespace is only for checking the design in Android Studio and this parameter won't be available in the real view.

For example, it is an error to use tools:textColor="#673AB7" instead of android:textColor="#673AB7" if you expect the app to display an special color for the text.

Advice: if you are new with Android, I suggest you start with simpler ViewGroups: LinearLayout or RelativeLayout instead of ConstraintLayout. You are probably expecting the EditText to be positioned with tools:layout_editor_absoluteX and tools:layout_editor_absoluteY.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/VSAC_page_heading"
        android:layout_width="376dp"
        android:layout_height="83dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="24dp"
        android:layout_marginEnd="16dp"
        android:gravity="center"
        android:text="Volume and Surface Area of Cubes and Cuboids"
        android:textColor="#673AB7"
        android:textSize="26sp"
        android:textStyle="bold|italic"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="24dp"
        android:ems="10"
        android:inputType="textPersonName"
        android:hint="Name"
        android:textColor="#673AB7"
        android:gravity="center"
        app:layout_constraintTop_toBottomOf="@+id/VSAC_page_heading"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
Fer
  • 1,956
  • 2
  • 28
  • 35
  • Thanks a lot! I am new to Android Studio and I didn't use XML for setting attributes, but I guess I'll have to now. –  Apr 24 '20 at 07:30