gpt4 book ai didi

android - 如何更改默认 EditText 的样式

转载 作者:IT老高 更新时间:2023-10-28 21:47:50 26 4
gpt4 key购买 nike

我正在使用这样的代码在我的 xml 文件中创建三个 EditText:

<EditText
android:id="@+id/name_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/profile_image_view_layout"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:ems="15"
android:hint="@string/name_field"
android:inputType="text" />

当我运行应用程序时,它在我的设备上看起来像这样:

enter image description here

但我希望它看起来像这样,不使用任何背景图片:

enter image description here

那怎么做呢?任何想法或建议都会有所帮助。

最佳答案

创建像edit_text_design.xml这样的xml文件并将其保存到您的drawable文件夹中

我已根据我的选择给出了颜色代码,请根据您的选择更改颜色代码!

 <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item>
<shape>
<solid android:color="#c2c2c2" />
</shape>
</item>

<!-- main color -->
<item
android:bottom="1.5dp"
android:left="1.5dp"
android:right="1.5dp">
<shape>
<solid android:color="#000" />
</shape>
</item>

<!-- draw another block to cut-off the left and right bars -->
<item android:bottom="5.0dp">
<shape>
<solid android:color="#000" />
</shape>
</item>

</layer-list>

你的编辑文本应该包含它作为背景:

android:background="@drawable/edit_text_design" 添加到您的所有 EditText

您上面的 EditText 现在应该如下所示:

      <EditText
android:id="@+id/name_edit_text"
android:background="@drawable/edit_text_design"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/profile_image_view_layout"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:ems="15"
android:hint="@string/name_field"
android:inputType="text" />

关于android - 如何更改默认 EditText 的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17449169/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com