首页 > 解决方案 > Material Design 中的大纲编辑文本

问题描述

我怎样才能实现一个概述的文本字段(如这个材料设计页面所示)? 激活的编辑文本

标签: androidandroid-layoutandroid-edittextmaterial-designandroid-textinputlayout

解决方案


阅读Outline Box

大纲文本字段有一个描边边框并且不太强调。要使用大纲文本字段,请将以下样式应用于您的 TextInputLayout:

 style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"

依赖项

implementation 'com.android.support:design:28.0.0-alpha1' 

XML

   <android.support.design.widget.TextInputLayout
   android:id="@+id/name_text_input"
   style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   >

   <android.support.design.widget.TextInputEditText
       android:id="@+id/name_edit_text"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:hint="@string/label_name" />
</android.support.design.widget.TextInputLayout>

DEMO

供参考

旧版支持在 Android 28 中结束。现在继续使用

implementation 'com.google.android.material:material:1.3.0'

推荐阅读