How to put a border in an EditText? [duplicate]

2019-09-24 10:41发布

This question already has an answer here:

anybody could tell me, how to put a border in an editText in AndroidStudio?

for example a square in an editText.

2条回答
贼婆χ
2楼-- · 2019-09-24 11:05

just try this one,

first create one XML file, inside drawable folder (use new drawable xml) and add this lines

<?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"/>

then add this line inside Your edittext property

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

i don't know what your expecting, maybe it will help you

查看更多
啃猪蹄的小仙女
3楼-- · 2019-09-24 11:25

It's so easy bro

First step create an shape.xml in your directory drawable

<?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>

Second step create your editext in your layout.xml and put background with the shape that you created above

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

It's all

查看更多
登录 后发表回答