0

I'm creating a custom drawable so that an EditText on top of a map has rounded corners. I'm trying to obey the correct parameters in the docs for shape. Specifically I am trying to set a white background using the solid field:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="5dp" />
    <solid android:color="#FFFFFF"/>
</selector>

and

<EditText
...
android:background="@drawable/text_box"
.../>

But the EditText is still transparent - I don't want the map to be visible behing the EditText. enter image description here

lf215
  • 1,185
  • 7
  • 41
  • 83

1 Answers1

1

You should create your resource first the drawable shape corner and background params:

myshape.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <corners android:radius="5dp"/>
    <solid android:color="#BFFFFFFF"/>
</shape>

myselector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="5dp" />
    <solid android:drawable="@drawable/myshape"/>
</selector>

And use the selector inside your edittext:

<EditText
...
android:background="@drawable/myselector"
.../>

BF... is for 75% opacity. Here you can found all opacity

Community
  • 1
  • 1
mcatta
  • 481
  • 5
  • 12
  • Is it possible to do this with one additional file instead of two? Can you please explain why this works and my solution does not work? – lf215 May 22 '16 at 06:43
  • You can use only myshape.xml if you want: **android:background="@drawable/myspahe"** .Generally you use selector if you need to specialize drawable for specific cases for example: a drawable for focus state another one for pressed state etc.. – mcatta May 22 '16 at 09:46