user3383415
user3383415

Reputation: 435

Remove EditText´s border

How can I quit the border to the EditText and show border in a color when I click to write in this EditText? Thank you.

enter image description here

Upvotes: 1

Views: 670

Answers (2)

MohdTausif
MohdTausif

Reputation: 508

try this:

define edittext like below:

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

on clicking at edit text set a background drawable in edittext, see below

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

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

});

define border drawable like below:

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

you can remove padding and borders element from drawable according to your requirement.

Upvotes: 0

Hariharan
Hariharan

Reputation: 24853

Try this..

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

EDIT

   editext.setOnClickListener(new OnClickListener(){

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

    });

Or

   editext.setOnTouchListener(new OnTouchListener(){

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

    });

Upvotes: 3

Related Questions