在我的应用程序中,我想在 TextInputLayout
中显示 View 。
我想要显示 EditText
、TextView
(用于显示 countDownTimer)和 View
(用于显示行)!
如下图:
我写了下面的代码,但我只能显示 EditText 而不能显示任何其他 View ,例如 TextView 和 View!
我的 XML 代码:
<android.support.design.widget.TextInputLayout
android:id="@+id/signInFrag_phoneInpLay"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="32dp"
android:layout_marginRight="32dp"
android:layout_marginBottom="8dp"
app:boxStrokeColor="@color/colorAccent"
app:boxStrokeWidth="1dp">
<EditText
android:id="@+id/edtLogin1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:drawableEnd="@drawable/ic_phone"
android:drawableRight="@drawable/ic_phone"
android:gravity="right|center_vertical"
android:hint="Phone Number"
android:inputType="phone"
android:maxLength="11"
android:maxLines="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:textColorHint="#c0c0c0"
android:textSize="12sp" />
</android.support.design.widget.TextInputLayout>
如何更改我的代码以显示如上图所示的代码?
最佳答案
您可以通过 constraintLayout 将 View 设置为重叠在 textInputLayout
上。可能存在将 editText 的文本与计数文本或垂直 View 重叠的风险。但我在您的 TextView 中发现有文本限制。所以出于您的原因,不可能重叠计数 TextView 。
代码 **
<?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"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search Page"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/input_layout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:boxStrokeColor="@color/colorAccent"
app:boxStrokeWidth="1dp"
app:hintEnabled="true"
app:layout_constraintTop_toBottomOf="@+id/title">
<EditText
android:id="@+id/edtLogin1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:drawableStart="@drawable/ic_action_profile"
android:gravity="left|center_vertical"
android:hint="Phone Number"
android:inputType="phone"
android:maxLength="11"
android:maxLines="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:textColorHint="#c0c0c0"
android:textSize="12sp" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="@+id/text_view_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="22sec"
app:layout_constraintBottom_toBottomOf="@+id/input_layout"
app:layout_constraintEnd_toEndOf="@+id/input_layout"
app:layout_constraintTop_toTopOf="@+id/input_layout" />
<View
android:id="@+id/view"
android:layout_width="1dp"
android:layout_height="0dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:background="@color/colorPrimary"
app:layout_constraintBottom_toBottomOf="@+id/input_layout"
app:layout_constraintEnd_toStartOf="@+id/text_view_time"
app:layout_constraintTop_toTopOf="@+id/input_layout" />
</androidx.constraintlayout.widget.ConstraintLayout>
关于android - 如何在 Android 上将一些 View 设置为 TextInputLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57182975/