Android EditText设置边框
程序员文章站
2022-07-04 20:06:36
...
简述
在Android4.0以后,EditText默认的是一条下划线,如果要设置边框,就得自己给EditText设置backgroud,在drawable自定义xml 作为EditText的背景,具体代码如下:
edittext_backgroud.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/transparent" />
<corners
android:radius="3px"
/>
<stroke
android:width="1px"
android:color="#FFFFFF"/>
</shape>
</item>
</layer-list>
2.应用
mEdt = new EditText(this);
mEdt.setHint(this.getResources().getString(R.string.edt_tips));
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(200, 50);
layoutParams.leftMargin = left;
layoutParams.topMargin = top;
layoutParams.rightMargin = right;
layoutParams.bottomMargin = bottom;
mEdt.setLayoutParams(layoutParams);
mEdt.setTextSize(10);
mEdt.setBackgroundResource(R.drawable.edit_bg);
上一篇: CSS选择器类型
下一篇: iframe 无边框设置