【发布时间】:2021-04-06 04:27:14
【问题描述】:
在我的应用程序中,我想使用 TextInputLayout 并为此视图设置边框。
比如这张图片:Image
我写以下代码:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/loginFrag_phoneInputLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_15mdp"
android:layout_marginLeft="@dimen/_15mdp"
android:layout_marginTop="@dimen/_15mdp"
android:layout_marginEnd="@dimen/_15mdp"
android:layout_marginRight="@dimen/_15mdp"
android:hint="@string/insertYourPhoneNumber"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/loginFrag_title">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/signInFrag_phoneEdt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:gravity="right|center_vertical"
android:inputType="phone"
android:maxLength="11"
android:maxLines="1"
android:paddingLeft="@dimen/_10mdp"
android:paddingRight="@dimen/_10mdp"
android:singleLine="true"
android:textColorHint="@color/colorLightGray"
android:textSize="@dimen/_10mdp"
app:drawableRightCompat="@drawable/ic_phone" />
</com.google.android.material.textfield.TextInputLayout>
我添加了这一行:
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
但是当将材料设计库更新到 v1.3 时不会显示任何边框!
'com.google.android.material:material:1.3.0'
但在 v1.2 或 v1.1 中显示边框并没有任何问题!
为什么不在 v1.3 中显示边框?
我该如何解决?
【问题讨论】:
-
如何将它包裹在一个有背景的视图中并给它一些边距?例如,
-
基本上你希望一个电话图标应该显示在编辑框中,这就是为什么你使用 app:drawableRightCompat="@drawable/ic_phone" 以及透明背景来使图标可见,我正确吗?
-
@NRUSINGHAMOHARANA,是的,但我该如何解决?
-
在 TextInputLayout 中使用 app:startIconDrawable="@drawable/ic_action_phone" 并从 TextInputEditText 中删除 android:background="@android:color/transparent" 和 app:drawableRightCompat="@drawable/ic_phone"。我更新了我的答案。
-
在theme.xml中你还需要设置材质主题prntscr.com/115fzwe
标签: android xml android-layout material-design android-textinputlayout