Question

its something you may think is duplicated question but i could not found simple solution .

i want edittext to be with border when focus .

this is what i try'd , if you have simple or better solution i will be happy to read .

define shape xml :

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#80000000" />
    <stroke android:width="2dp" android:color="#5480F7" />
    <padding android:left="1dp" android:top="1dp" android:right="1dp"
        android:bottom="1dp" />

</shape>

this simple <shape> create border with transparent background .

define xml for edittext :

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/edittext_border" android:state_focused="true" />
    <item android:drawable="@drawable/notfocus"/> <!-- default -->

</selector>

the problem here is that the xml that create the border is insert to my edittext as drawable meaning that i cant change the background image for the edittext .

i want my edittext to be with spcefic background image and when focus i want the image to stay but will be with border .

thanks .

Was it helpful?

Solution 2

make One background image with border and other will be just background of focus set with border else without border.

OTHER TIPS

You can achieve it by two ways:

  1. By creating two different image for the EditText.
  2. By creating two different shape color for the EditText.

    1. By two different image: Just follow Siddhesh comment to achieve this.
    2. By Different shape for EditText: you have done right with this way. but i think you have enter wrong background color code to solid attribute.

add:

<solid android:color="#00000000" />

instead of:

   <solid android:color="#80000000" />

Hope this help you. If not then let me know. Will like to help you.

Enjoy Coding... :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top