【发布时间】:2020-11-30 06:58:57
【问题描述】:
我正在尝试使用 Outline Boarder 创建一个 TextInputLayout。但是,每当我使用以下样式时,应用程序都会出现故障(崩溃)。
在发布之前,我已经尝试了 stackoverflow 内外列出的所有解决方案,但到目前为止还没有解决问题。
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
当前布局
<ScrollView...
<LinearLayout
android: layout_width = "200dp"
android: layout_height = "wrap_content"
android: orientation = "vertical"
android: layout_marginTop = "2dp" >
<com.google.android.material.textfield.TextInputLayout
android: id = "@+id/outlinedTextField"
android: layout_width = "match_parent"
android: layout_height = "wrap_content"
android: hint = "@string/label"
style = "@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app: boxStrokeWidthFocused = "2dp"
app: boxStrokeColor = "@color/border_primary" >
<com.google.android.material.textfield.TextInputEditText
android: layout_width = "match_parent"
android: layout_height = "wrap_content" />
</LinearLayout>
</ScrollView>
完整布局:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
tools:context=".user.userprofile.UserProfileFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="@layout/user_profile_header"/>
<LinearLayout
android:layout_width="200dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/outlinedTextField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android: hint = "@string/label"
app:hintTextColor="@color/text_primary"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:boxStrokeWidthFocused="2dp"
app:hintTextColor="@color/text_primary"
app:boxStrokeColor="@color/border_primary">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
更多信息:当添加style 时,hint 失去焦点。也没有出现边框。
【问题讨论】:
-
嘿@Rootster,我不知道您所说的故障具体是什么意思,但是
TextInputEditText是在TextInputEditText内部使用的。请粘贴您的完整 xml 以及您的故障到底是什么。也许我可以帮忙 -
确实有必要知道确切的“故障”是什么。而@ravi 的意思是
TextInputEditText必须在TextInputLayout里面(他打了一个小错字) -
每次启动时应用程序崩溃的故障。但是当我删除
style = "@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"它工作正常。另外我想补充一下,当我使用上述样式时,“提示”也会失焦。
标签: android android-studio android-layout