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.
Asked
Active
Viewed 592 times
2 Answers
3
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;
}
});

Hariharan
- 24,741
- 6
- 50
- 54
-
With the code you have tell to me the Edit text looks like the image of the left that I have put. But when I click in the Edit Text to write the border not appear, I want that when I click in the Edit text a red border appear like the image of the right. Thanks – user3383415 Apr 16 '14 at 15:38
-
@user3383415 Is that border in drawable folder. I edited Check it. – Hariharan Apr 16 '14 at 15:41
-
@user3383415 You can see it. – Hariharan Apr 16 '14 at 15:46
0
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.

MohdTausif
- 498
- 4
- 13