Search code examples
javaandroidxmlkotlinlayout

Why layout editor in android studio working incorrectly?


I have the problem, which is that layout editor in android studio displays layout incorrectly.screen from android studio

I think that is layout haven't missing some attribute like xmlns:tools="".

It looks like your post is mostly code; please add some more details. It looks like your post is mostly code; please add some more details :D

Layout code is below `

<TextView
    android:id="@+id/tv_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="52dp"
    android:text="@string/registration_title"
    android:textSize="30sp" />

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/name_input_layout"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="48dp"
    app:counterEnabled="true"
    app:counterMaxLength="25"
    app:errorEnabled="true">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/et_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/registration_hint_name" />

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/login_input_layout"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    app:counterEnabled="true"
    app:counterMaxLength="25"
    app:errorEnabled="true">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/et_login"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:hint="@string/registration_hint_login" />

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/password_input_layout"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    app:counterEnabled="true"
    app:counterMaxLength="25"
    app:endIconMode="password_toggle"
    app:errorEnabled="true">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/et_password"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:inputType="textPassword"
        android:hint="@string/registration_hint_password" />

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/repeated_password_input_layout"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    app:counterEnabled="true"
    app:endIconMode="password_toggle"
    app:counterMaxLength="25">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/et_repeated_password"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:inputType="textPassword"
        android:hint="@string/registration_hint_password_repeat" />

</com.google.android.material.textfield.TextInputLayout>

<Button
    android:id="@+id/btn_register"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="32dp"
    android:text="@string/registration_button_register" />


</LinearLayout>

`


Solution

  • In Android Studio, the layout that is shown in editor is just a preview that does not know about the theme which we set in AndroidManifest.xml. So we should change the theme in the editor to see the correct preview.

    Well, To change the theme just select the correct theme in the top of your editor. (the dropdown which is selected "Light" in your picture that you shared)