android-textinputlayout 相关问题

由于用户输入文本而隐藏提示时,包装EditText(或后代)以显示浮动标签的布局。

以编程方式更改 TextInputLayout 聚焦和非聚焦提示颜色

我想在 TEXT INPUT LAYOUT 处于聚焦或未聚焦状态时更改相同的提示颜色。我有两个 TEXT INPUT LAYOUT 字段。两个字段的颜色相同。但它处于聚焦状态颜色

回答 4 投票 0

如何在 Jetpack Compose 中使用可搜索下拉菜单保持键盘焦点?

我正在尝试在 Jetpack Compose 中实现可搜索的下拉菜单,但每当下拉菜单出现时,键盘就会失去焦点并消失。如何修改代码来防止键盘...

回答 1 投票 0

删除 TextInputLayout 额外的顶部填充

TextInputLayout 似乎总是在顶部有一些额外的填充(无论所有边距/填充都设置为 0): 布局如下: TextInputLayout 似乎总是在顶部有一些额外的填充(无论所有边距/填充都设置为 0): 布局如下: <android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.AppCompatEditText android:id="@+id/txt_amount" style="@style/EditTextStyle" android:hint="@string/hint_amount" android:inputType="numberDecimal"/> </android.support.design.widget.TextInputLayout> 如何删除这个多余的空间? 您可以通过将 app:hintEnabled="false" 设置为 TextInputLayout 来删除 AppCompatEditText 上方的额外空间,但在您重新启用之前它不会显示提示。 有关更多信息,请访问 Android 开发者网站 -TextInputLayout 查看以下代码 <android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" app:hintEnabled="false"> <android.support.v7.widget.AppCompatEditText android:id="@+id/txt_amount" style="@style/EditTextStyle" android:hint="@string/hint_amount" android:inputType="numberDecimal"/> </android.support.design.widget.TextInputLayout> 希望这有帮助.. @拉杰什 接受的答案在版本上对我不起作用 - 1.2.1所以我做了一些实验并意识到填充实际上并不是来自TextInputLayout,而是来自TextInputEditText。所以首先我从中删除了填充,但它看起来不均匀,所以我将自定义填充设置为 TextInputEditText 并且效果很好。只需将此行 android:padding="16dp" 添加到 TextInputEditText 将 16dp 替换为您想要的值即可。 具有这样的结构: <com.google.android.material.textfield.TextInputLayout android:id="@+id/til_project" style="@style/LoginTextInputLayoutStyle" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" app:errorEnabled="false"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/totalPiecesProduct" android:layout_gravity="center" android:gravity="center" android:padding="0dp" android:textSize="13sp" style="@style/TextInputEditTextStyle"/> </com.google.android.material.textfield.TextInputLayout> 按键是: app:errorEnabled="false" 在 TextInputLayout `android:padding="0dp"` in `TextInputEditText` 之前: 之后 要删除 TextInputLayout 中的所有填充,您可以在 TextInputLayout 中将 app:boxCollapsedPaddingTop 设置为 0dp,在 Edittext 中将 android:padding 设置为 0dp。 您可以通过覆盖TextInputStyle的默认填充样式来实现,(Material版本应高于1.1.0) <style name="CustomInputLayoutPadding" parent="Widget.MaterialComponents.TextInputLayout.FilledBox"> <item name="boxBackgroundColor">@color/transparent</item> <item name="materialThemeOverlay">@style/CustomOverlayFilledPadding</item> </style> 然后 <style name="CustomeOverlayFilledPadding"> <item name="editTextStyle">@style/CustomTextInputEditPaddingStyle</item> </style> 然后 <style name="CustomTextInputEditPaddingStyle" parent="@style/Widget.MaterialComponents.TextInputEditText.FilledBox"> <item name="android:paddingStart" ns2:ignore="NewApi">2dp</item> <item name="android:paddingEnd" ns2:ignore="NewApi">2dp</item> <item name="android:paddingLeft">0dp</item> <item name="android:paddingRight">2dp</item> <item name="android:paddingTop">28dp</item> <item name="android:paddingBottom">12dp</item> </style> 我已经在 TextInputEditText 中使用设置手动填充 android:paddingHorizontal="@dimen/_12sdp" android:paddingVertical="@dimen/_10sdp" 从 compileSdk 33 或材质库版本 v1.8.0 开始,我添加了属性 app:boxBackgroundMode="filled" 在<com.google.android.material.textfield.TextInputLayout 将 hintEnabled = false 添加到布局 XML 中的 TextInputLayout。 你可以用这个 <android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:textColorHint="@android:color/white"> <com.bugle.customviews.RobotoLightEditText android:id="@+id/edtName" style="@style/StyledTilEditText" android:hint="@string/name" android:imeOptions="actionNext" android:inputType="textCapWords" /> </android.support.design.widget.TextInputLayout> 在 EditText 中添加这一行 android:translationY="-10dp"

回答 10 投票 0

相当于 Jetpack Compose TextField 中的“expandedHintEnabled”

当 OutlinedTextField 未处于焦点时,有什么方法可以将 OutlinedTextField 的标签放在顶部(展开)并且仍然具有占位符? 在 xml 布局中,我们有 TextInputLayout ,它有

回答 1 投票 0

当用户触摸下拉菜单时隐藏软键盘

我的应用程序中公开了以下 Android Material 组件的下拉菜单: 我的应用程序中公开了以下 Android Material 组件的下拉菜单: <com.google.android.material.textfield.TextInputLayout android:id="@+id/drop_down_menu" style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_marginEnd="8dp" android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar" app:boxBackgroundColor="@android:color/white" app:layout_constraintBottom_toBottomOf="@+id/number_text_view" app:layout_constraintEnd_toStartOf="@+id/add_button" app:layout_constraintTop_toTopOf="@+id/number_text_view"> <com.google.android.material.textfield.MaterialAutoCompleteTextView android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="none" android:paddingStart="8dp" android:paddingEnd="8dp" /> </com.google.android.material.textfield.TextInputLayout> 当用户触摸下拉菜单并出现菜单选项时,如何隐藏片段中的软键盘?当用户单击 EditText 组件并且在触摸下拉菜单关闭键盘之前未触摸屏幕的其他部分时,键盘会显示。 您可以将focusChangeListener注册到MaterialAutoCompleteTextView并在获得焦点时隐藏键盘。 autoCompleteTextView.setOnFocusChangeListener { v, hasFocus -> if (hasFocus) { hideSoftKeyboard() // Using activity extension function // v.hideKeyboard() // Using view extension function } } 这是隐藏键盘的 Activity 扩展功能: fun Activity.hideSoftKeyboard() { val inputMethodManager = this.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager val currentFocus = this.currentFocus val windowToken = this.window?.decorView?.rootView?.windowToken inputMethodManager.hideSoftInputFromWindow(windowToken, 0) inputMethodManager.hideSoftInputFromWindow( windowToken, InputMethodManager.HIDE_NOT_ALWAYS ) if (currentFocus != null) { inputMethodManager.hideSoftInputFromWindow(currentFocus.windowToken, 0) } } 或者您可以在 View 本身上使用以下内容。 来源 fun View.hideKeyboard(): Boolean { try { val inputMethodManager = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager return inputMethodManager.hideSoftInputFromWindow(windowToken, 0) } catch (ignored: RuntimeException) { } return false } } bindingSheet.dropDownFloorList.setOnFocusChangeListener { v, hasFocus -> if (hasFocus) { hideSoftKeyboard() // Using activity extension function // v.hideKeyboard() // Using view extension function } }

回答 2 投票 0

使用TextInputEditText时,错误图标会覆盖结束图标

我正在开发一个包含 TextInputLayout 组件的界面。 这是我的布局代码: 我正在开发一个包含 TextInputLayout 组件的界面。 这是我的布局代码: <com.google.android.material.textfield.TextInputLayout style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox" android:id="@+id/username_label" android:layout_width="match_parent" android:layout_height="wrap_content" app:startIconDrawable="@drawable/icons8_user_24" app:endIconMode="custom" app:endIconDrawable="@drawable/icons8_user_24" app:errorEnabled="true" android:hint="Enter UserName" android:textColorHint="@color/teal_200"> <com.google.android.material.textfield.TextInputEditText android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/edit_text" android:inputType="text" /> </com.google.android.material.textfield.TextInputLayout> 这是java代码: UsereditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (s != null && !isEmailAddress(s.toString())) { UsereditText.setError("Error Address"); } else { UsereditText.setError(null); } } @Override public void afterTextChanged(Editable s) { } }); 结果图像是: 不过我看到有人做得很完美,不知道怎么做的。 我现在很情绪化,请帮忙! 谢谢。 更新答案(添加更多信息后) 尝试在 TextInputLayout 而不是 TextInputEditText 上调用 setError()。然后,视图本身将确保错误图标不会与结束图标重叠。 不要将编辑图标放置为背景可绘制对象,尝试将其放置为drawableEnd: <com.google.android.material.textfield.TextInputEditText android:layout_width="match_parent" android:layout_height="wrap_content" android:drawableEnd="@drawable/edit_text" android:inputType="text" /> 更新答案 实际上,我正在遵循下面的 XML 代码 <com.google.android.material.textfield.TextInputLayout android:id="@+id/enter_mail_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="@dimen/dimen_20dp" android:layout_marginEnd="@dimen/dimen_20dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/mail" style="@style/TextViewStyleRegular" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/white" android:hint="@string/enter_mail_2" android:inputType="textEmailAddress|textNoSuggestions" android:maxLength="50" /> </com.google.android.material.textfield.TextInputLayout> Kotlin 代码 binding.enterMailText.setErrorIconDrawable(R.drawable.no_icon) binding.enterMailText.error = "Please enter valid email address" no_icon.xml <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> </selector> 这对我有用: 绑定.yourInputLayout.errorIconDrawable = null

回答 3 投票 0

如何在TextInputLayout上显示成功状态(类似setError())

我需要在Material的TextInputLayout上显示成功状态。我只需要与设置错误时显示的布局相同的 UI。以下是我需要的: 类自定义文本输入布局( 上下文:

回答 1 投票 0

Android 自定义 TextInput 布局,提示文本和占位符重叠

我在使用自定义 TextInputLayout 时遇到一个奇怪的问题,其中我同时具有提示文本和占位符文本,一般情况下,当焦点位于编辑文本上时,提示文本会向上浮动并

回答 1 投票 0

EditText TextInputLayout 提示文本对齐:有没有办法像 EditText 视图的 textAlignment 属性一样对齐提示文本

我有一个固定高度的输入文本字段(TextInputLayout 的 EditText)。 我想将提示文本与视图的左上角对齐。 问题:提示文本总是显示在 center_verticle 但我想dis...

回答 5 投票 0

更改TextInputLayout的下划线颜色和浮动提示颜色

我在 TextInputLayout 主题中使用上述属性,使 TextInputLayout 激活时的下划线颜色为绿色。 #27e905...

回答 5 投票 0

如何更改textinputlayout内textinputedittext中的光标颜色

如何更改textinputedittext的光标颜色。 我使用了 textcursordrawable 但它不起作用。 预先感谢

回答 2 投票 0

jetpack compose 中带有提示文本的 TextField

我想在 jetpackcompose 中创建带有提示文本的文本字段。任何如何使用 jectpack 创建文本字段的示例?谢谢

回答 9 投票 0

如何删除 TextInputLayout 可绘制填充?

我在 TextInputLayout 中使用 ExitText 并启用 `` 应用程序:passwordToggleEnabled =“true” 并切换视图如下 我想删除切换按钮的右侧填充,但不知何故无法...

回答 3 投票 0

Android TextInputLayout endIconDrawable 显示为灰色而不是图像

TextInputLayout endIconDrawable 显示为灰色而不是所需的图像。 只有该图像呈现为灰色。我尝试将图像作为 png 并导入 svg 作为矢量资源。 两者都不起作用

回答 2 投票 0

Android Material 文本输入布局结束图标不显示

我正在尝试向我的文本输入布局添加一个可绘制的结束图标。我已经遇到了这样做的方法,但是当我尝试实现它时,它不起作用。 Material io 说这一切都需要

回答 6 投票 0

如何在TextInputLayout错误消息中显示可点击的链接,android中的app:setError

我有一个文本输入字段,将名称作为输入。该布局在 TextInputLayout 内包含一个 EditText 小部件。当用户输入为空时,我想显示错误验证消息...

回答 1 投票 0

TextInputEditText 当以编程方式设置字段值时,提示保留在后台

我确定用户的位置并将其显示在 TextInputEditText 字段中。然而,这一提示仍然存在于背景中。我究竟做错了什么? 我确定用户的位置并将其显示在 TextInputEditText 字段中。然而,这一提示仍然存在于背景中。我做错了什么? <com.google.android.material.textfield.TextInputLayout android:id="@+id/textLayoutAutocomplete" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/standort" android:layout_weight="1"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/autocomplete" android:focusableInTouchMode="false" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="text" /> </com.google.android.material.textfield.TextInputLayout> 设置值:: binding.autocomplete.setText(place.toString()) //Also not working: //binding.textLayoutAutocomplete.hint = "" 设置文字后,可以将isHintEnabled的TextInputLayout设置为false。 binding.textLayoutAutocomplete.isHintEnabled = false

回答 1 投票 0

如何正确从Material Design TextInputLayout获取文本?

我想使用自定义结束图标从材料设计的 TextInputLayout 中获取文本。 我尝试这样做: TextInputLayout textInputCustomEndIcon = findViewById(R.id.editText); 最终的 TextInputEdi...

回答 6 投票 0

Jetpack Compose 如何去除 EditText/TextField 下划线并保留光标?

嗨,我需要删除文本字段中的下划线,因为当文本字段是圆形时它看起来很丑。我已将 activeColor 设置为透明,但光标不会显示(因为它是透明的...

回答 3 投票 0

如何防止键盘打开时MaterialAlertDialogBuilder高度自动调整大小?

我使用 MaterialAlertDialogBuilder 构建了一个自定义对话框。该对话框有 2 个 TextInputLayout。问题是当我尝试在 TextInputEditText 中写一些东西并且键盘可见时......

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.