代码之家  ›  专栏  ›  技术社区  ›  Nominalista

如何从OutlinedBox样式的TextInputLayout中删除浮动标签?

  •  0
  • Nominalista  · 技术社区  · 6 年前

    有没有办法删除浮动标签(提示)当 TextInputLayout 是否处于聚焦模式?

    当我试着 app:hintEnabled="false" 在里面暗示 TextInputeEditText ,的 文本输入布局 通过隐藏顶部笔划来表现怪异。

    <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.

    编辑

    Screenshot

    上划被切断。

    2 回复  |  直到 6 年前
        1
  •  4
  •   ErikusMaximus    5 年前

    只是给你一个暗示 EditText app:hintEnabled="false" 从你的 TextInputLayout

        2
  •  3
  •   Joen93    4 年前

    TextInputLayout .

    文本输入布局 ,并在 TextInputEditText 而不是

    <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>
    

    结果如下所示: enter image description here

    当添加一些文本时,它将如下所示: enter image description here

    我在materialcomponents v1.2.0中尝试过这个

        3
  •  0
  •   DeePanShu    6 年前

    尝试 将提示设置为空 文本布局和编辑text:-

    <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>
    

    如果你 想用吗 那你就可以了 使用自定义可绘制作为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>
    
        4
  •  0
  •   milad salimi    6 年前

    您首先应该使用此样式:

    <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>