im new to android and java, this is my 1st building login page for my project app, confuse with android studio layout,
My login page username text and password text position are different! anyone have any suggestion for my coding?
<LinearLayout
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"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity"
tools:ignore="ExtraText">
<ImageView
android:id="@ id/item_image"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center"
android:src="@drawable/eschool"
app:layout_constraintBottom_toTopOf="@ id/title" />
<TextView
android:id="@ id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="PLT MUAR 行政系统"
android:textColor="@color/black"
android:textSize="35dp"
android:textStyle="bold" />
<TextView
android:id="@ id/ID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="126dp"
android:gravity="left"
android:text="用户名 UserID:"
android:textColor="@color/black"
android:textSize="16sp"
android:textStyle="bold"
tools:ignore="RtlHardcoded" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="55dp"
android:gravity="left"
android:layout_marginTop="5dp"
android:background="@drawable/login_column">
this my username text part:
<EditText
android:id="@ id/et_username"
android:layout_width="340dp"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:textSize="20sp"
android:background="@android:color/transparent"
android:selectAllOnFocus="true"
android:inputType="text|textUri"
android:textColor="@android:color/black"
android:textColorHint="@android:color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
This my password part below:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="密码 Password:"
android:textColor="@color/black"
android:textSize="16sp"
android:layout_marginTop="10dp"
android:layout_marginRight="124dp"
android:textStyle="bold" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="10dp">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="355dp"
android:layout_height="60dp"
android:layout_marginBottom="0dp"
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@ id/et_password"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="0dp"
android:inputType="textPassword"
android:background="@drawable/login_column"
android:selectAllOnFocus="true"
android:textColor="@android:color/black"
android:textColorHint="@android:color/black"
android:textSize="20sp" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<Button
android:id="@ id/bt_submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:background="@drawable/round_button"
android:text="Submit"
android:textColor="@android:color/white" />
any better suggestion for my front page?
CodePudding user response:
this is because for password you use TextInputLayout with TextInputEditText and for username you use EditText, for username instead EditText use TextInputLayout with TextInputEditText as in password example:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="355dp"
android:layout_height="60dp"
android:layout_marginBottom="0dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@ id/et_username"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="0dp"
android:background="@drawable/login_column"
android:selectAllOnFocus="true"
android:textColor="@android:color/black"
android:textColorHint="@android:color/black"
android:textSize="20sp" />
</com.google.android.material.textfield.TextInputLayout>