![](/img/trans.png)
[英]How to remove shadow from OutlinedBox TextinputLayput's floating label
[英]How to remove floating label from TextInputLayout with OutlinedBox style?
當TextInputLayout
處於聚焦模式時,有沒有辦法刪除浮動標簽(提示)?
當我嘗試在TextInputeEditText
設置app:hintEnabled="false"
和提示時, TextInputLayout
通過隱藏頂部筆觸表現app:hintEnabled="false"
奇怪。
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Text">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
重要的是我在1.1.0-alpha01.
版本中使用 Material Components 1.1.0-alpha01.
編輯
這是它的樣子(當輸入未聚焦時):
頂部行程被切斷。
只需以編程方式為EditText
設置提示,然后從TextInputLayout
刪除app:hintEnabled="false"
(如果有),就我而言是有效的:)
是的,有一種相當簡單的方法可以刪除浮動標簽提示,並且在TextInputLayout
只有一個提示。
這可以通過禁用TextInputLayout
的提示輕松實現,並在TextInputEditText
而不是TextInputLayout
上設置提示,如下所示:
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintEnabled="false">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="hint text comes here" />
</com.google.android.material.textfield.TextInputLayout>
我在 Material Components v1.2.0 中試過了
嘗試將文本布局和編輯文本的提示設置為空:-
<com.google.android.material.textfield.TextInputLayout
app:boxBackgroundMode="outline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:hint=""
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
如果你想使用提示,那么你可以使用自定義 drawable 作為 EditText 的背景:-
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="10dp"/>
<solid android:color="#ffffff"/>
<stroke android:color="#000000"
android:width="2dp"/>
</shape>
你應該首先使用這種風格:
<style name="TextInputLayoutOutlinedBoxStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="android:textColorHint">#F5F5F5</item>
<item name="hintTextAppearance">@style/HintTextAppearance</item>
<item name="boxCornerRadiusBottomEnd">20dp</item>
<item name="boxCornerRadiusBottomStart">20dp</item>
<item name="boxCornerRadiusTopEnd">20dp</item>
<item name="boxCornerRadiusTopStart">20dp</item>
</style>
你應該有包含這種樣式的 textinputlayout ,如下所示:
<com.google.android.material.textfield.TextInputLayout
style="@style/TextInputLayoutOutlinedBoxStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/relativelayout_activatetoken_main"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="20dp"
android:hint="@string/activatetoken_passwordhint"
android:textColorHint="@color/colorText"
app:helperText="@string/activatetoken_passwordhelpertext"
app:helperTextTextAppearance="@style/TextAppearanceHelper"
app:hintTextAppearance="@style/TextAppearanceBase"
app:passwordToggleTint="@color/text_50">
對於邊框顏色,在顏色中使用它:
<color name="mtrl_textinput_default_box_stroke_color" tools:override="true">#F5F5F5</color>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.