Gan*_*ake 9 android android-edittext material-design android-textinputlayout androidx
我正在登录屏幕上工作,我想在其中使用以下视图实现材料编辑文本:
以下是我的代码:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
style="@style/ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="This is Hint"/>
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
但是 OutlinedBox 没有出现。这是它的外观:
请帮忙。
小智 9
styles.xml主题如下,
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
Run Code Online (Sandbox Code Playgroud)
TextInputLayout 示例:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="@string/user_name" />
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
希望这对你有用!
用这个
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
Run Code Online (Sandbox Code Playgroud)
相反,这个
style="@style/ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox"
Run Code Online (Sandbox Code Playgroud)
示例代码
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="This is Hint"/>
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11185 次 |
| 最近记录: |