Zia*_* H. 3 android material-design android-textinputlayout material-components material-components-android
我正在使用 Material 设计库制作圆形的 editText,我能够做到这一点,但现在我希望它看起来更小,我使用了密集的 textField 样式,但我仍然希望视图的高度更小比起那个来说。问题是浮动 Label 标签,我没有为 textField 设置提示,但 Label 标签仍然占用一些空白空间。
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.Dense"
android:id="@+id/editText"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:endIconMode="custom"
app:endIconDrawable="@drawable/ic_speaker_24dp"
app:layout_constraintBottom_toBottomOf="@+id/topBar_view"
app:layout_constraintEnd_toEndOf="@+id/topBar_view"
app:layout_constraintStart_toEndOf="@+id/separater_line"
app:layout_constraintTop_toTopOf="parent"
app:boxCornerRadiusTopStart="20dp"
app:boxCornerRadiusTopEnd="20dp"
app:boxCornerRadiusBottomStart="20dp"
app:boxCornerRadiusBottomEnd="20dp">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
我只希望 textField 看起来像 chrome url 搜索栏,苗条,键入时提示消失,而不是浮动标签。
编辑:我尝试了该app:hintEnabled="false"属性,但仍有一个空白空间
Gab*_*tti 20
您可以使用app:hintEnabled="false"禁用浮动标签功能。您也可以自定义密集样式。
您可以使用以下内容:
<com.google.android.material.textfield.TextInputLayout
app:hintEnabled="false"
style="@style/MyDenseOutlined"
...>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
用这种风格:
<style name="MyDenseOutlined" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
<item name="materialThemeOverlay">@style/MyThemeOverlayOutlinedDense</item>
</style>
<style name="MyThemeOverlayOutlinedDense">
<item name="editTextStyle">@style/MyTextInputEditText_outlinedBox_dense_h
</item>
</style>
<style name="MyTextInputEditText_outlinedBox_dense_h" parent="@style/Widget.MaterialComponents.TextInputEditText.OutlinedBox.Dense">
<item name="android:paddingTop">8dp</item>
<item name="android:paddingBottom">8dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
这里的结果(具有默认样式和自定义样式):
| 归档时间: |
|
| 查看次数: |
3374 次 |
| 最近记录: |