【问题标题】:How to remove the border of edittextfield in android如何在android中删除edittextfield的边框
【发布时间】:2013-01-07 15:46:13
【问题描述】:

如何在 android.xml 中删除 Edittext 字段的边框。其实是这样的

http://pbrd.co/V34sN7

有了这个布局代码

    <EditText
        android:id="@+id/login_error"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text=""
        android:background="@android:drawable/editbox_background_normal"
        android:visibility="invisible" 
        android:textColor="#FF0000"
        android:layout_gravity="right"
        />

虽然我定义了它,但文本的对齐方式不在右侧。

谢谢

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    简单地说,您可以在xml 文件中使用以下内容来使EditText 背景清晰:

    android:background="@null"
    

    【讨论】:

      【解决方案2】:

      程序化方法:

      setBackgroundDrawable(null);
      

      或者,因为 setBackgroundDrawable() 在 API 16 中已被弃用:

      if (Build.VERSION.SDK_INT >= 16)
          setBackground(null);
      else
          setBackgroundDrawable(null);
      

      【讨论】:

      • 呃……我的整个 EditText 都变黑了,我什么都看不见。
      【解决方案3】:

      您可以使用以下 xml 布局自定义您的EditText

      以下代码另存为yourWishName.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <selector
      xmlns:android="http://schemas.android.com/apk/res/android">
      
      //You can change the color of the edit text here which removes the border line as well
       <item android:state_focused="true" >
          <shape android:shape="rectangle">
              <gradient
                  android:startColor="#FFFFFF"
                  android:endColor="#FFFFFF"
                  android:angle="270" />
              <stroke
                  android:width="3dp"
                  android:color="#F8B334" />
              <corners
                  android:radius="12dp" /> 
          </shape>
      </item>  
      <item>
          <shape android:shape="rectangle">
              <gradient
                  android:startColor="#FFFFFF"
                  android:endColor="#FFFFFF"
                  android:angle="270" />
              <stroke
                  android:width="0dp"
                  android:color="#000000" />
              <corners
                  android:radius="12dp" /> 
          </shape>
      </item>
      </selector>
      

      在 EditText 中调用 xml android:background="@drawable/yourWishName"

      右对齐使用android:gravity="right"

      希望对你有帮助

      【讨论】:

        【解决方案4】:

        您必须创建一个没有边框的自定义可绘制九个补丁文件。 Here you find a tutorialandroid:layout_gravity="right" not 表示文本右对齐。它将布局向右对齐。你必须使用android:gravity="right"

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2022-01-14
          • 2017-02-01
          • 1970-01-01
          • 1970-01-01
          • 2010-09-22
          • 1970-01-01
          • 2019-10-16
          • 1970-01-01
          相关资源
          最近更新 更多