I played this style in drawable to have edge in my Edittext, it worked but I didn’t understand anything of it

Asked

Viewed 92 times

1

I copied on the net this code to give an edge but do not understand why it has three items, someone help me?

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- most important is order of layers -->
    <!-- Bottom right side 2dp Shadow -->
    <item >
        <shape android:shape="rectangle">
            <solid android:color="#363636" />
        </shape>
    </item>

    <!-- Bottom 2dp Shadow -->
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#363636" />
        </shape>
    </item>

    <!-- White Top color -->
    <item android:bottom="3dp" android:right="3dp" android:top="3dp" android:left="3dp" >
        <shape android:shape="rectangle">
            <solid android:color="#FFFFFF" />
        </shape>
    </item>
</layer-list>
  • It seems that on android there is no concept of border. So they suggested to Voce create rectangles to have the same effect. It seems that the border also has different colors and they ended up creating 1 rectangle for each color.

  • 1

    @ramaral Voce left a repeated item unintentionally

  • 1

    @Brunocosta was no mistake. xml was not properly formatted, so only two appeared. What drew my attention to this was the AP mention 3 items and only appear 2.

  • @right ramaral I will erase.

1 answer

3


You’re right to wonder why you have 3 items.

In fact one of them is the extra.

One layer-list, as the name suggests, is a list of layers, in this case of Drawables.
Each of the Drawables is drawn on the previous.

Drawing two things equal, one on top of the other, is the same as drawing only one.
Can eliminate one of the first two that behavior is maintained.

The "edge" effect is achieved by superimposing a white rectangle on a color #363636. As the white rectangle is smaller, it leaves a portion of 3dp of the other.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.