【问题标题】:How to put a border in an EditText? [duplicate]如何在 EditText 中添加边框? [复制]
【发布时间】:2018-01-03 18:35:17
【问题描述】:

谁能告诉我,如何在 AndroidStudio 的 editText 中添加边框?

例如,editText 中的正方形。

【问题讨论】:

    标签: android android-layout android-edittext


    【解决方案1】:

    很简单啊

    第一步在你的drawable目录中创建一个shape.xml

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke 
        android:width="1dp"
        android:color="@android:color/black"/>
    </shape>
    

    第二步在你的 layout.xml 中创建你的 edittext 并使用你在上面创建的形状放置背景

    <EditText
        android:id="@+id/edittext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/shape"/>
    

    就是这样

    【讨论】:

      【解决方案2】:

      试试这个,

      首先在drawable文件夹中创建一个XML文件(使用新的drawable xml)并添加这一行

      <?xml version="1.0" encoding="utf-8"?>
      <shape xmlns:android="http://schemas.android.com/apk/res/android"
      android:shape="rectangle"/>      
      <solid android:color="#000000"/>
      <stroke
          android:color="#ffffff"
          android:width="05dp"/>
      <corners android:radius="20dp"/>
      

      然后在你的 edittext 属性中添加这一行

      android:background="@drawable/(file_name)"
      

      我不知道你的期望,也许它会帮助你

      【讨论】:

        猜你喜欢
        • 2017-11-20
        • 2014-10-18
        • 2012-10-15
        • 1970-01-01
        • 1970-01-01
        • 2019-12-26
        • 2022-01-14
        • 2017-04-09
        • 1970-01-01
        相关资源
        最近更新 更多