删除EditText的边框

时间:2014-04-16 15:16:36

标签: android

当我在此EditText中单击以写入时,如何退出EditText的边框并以颜色显示边框?谢谢。

enter image description here

2 个答案:

答案 0 :(得分:3)

试试这个..

<EditText  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:background="@null"
//Or
android:background="#00000000"
//Or
android:background="@android:color/transparent"
/>

修改

   editext.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            editext.setBackgroundResource(R.drawable.border);
        }

    });

或者

   editext.setOnTouchListener(new OnTouchListener(){

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            editext.setBackgroundResource(R.drawable.border);
            return true;
        }

    });

答案 1 :(得分:0)

试试这个:

定义如下所示的edittext:

 <EditText  
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="@null"
    />

点击编辑文字时,在edittext中设置背景可绘制,见下文

editext.setOnTouchListener(new OnTouchListener()
{
    @Override
    public boolean onTouch(View v, MotionEvent event) 
    {

        editext.setBackground(R.drawable.border);
        return true;
    }

});

定义边框可绘制如下:

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="@color/white"/>    

    <stroke android:width="1dp" android:color="@color/red"/>

    <padding android:left="5dp"
             android:top="5dp"
             android:right="5dp"
             android:bottom="5dp"
             /> 

    <corners android:bottomRightRadius="3dp" android:bottomLeftRadius="3dp" 
     android:topLeftRadius="3dp" android:topRightRadius="3dp"/> 
</shape>

您可以根据自己的要求从drawable中删除填充和边框元素。