Add drop shadow effects to EditText Field

后端 未结 3 2081
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-01 03:47

I am trying to design an EditText Field having Shadows (bottom and right side) like this

\"ente

相关标签:
3条回答
  • 2020-12-01 04:33

    Well.. @Shalini's answer helped me in this way but still I got another way to achieve 2D shadow with EditText Field and I am going to share with you.

    We need to create custom XML view with three layer for EditText, bottom shadow and right side shadow

    Below is my code.

    res/drawable/edittext_shadow.xml

    <?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="#000000" />           
            </shape>
        </item>
    
        <!-- Bottom 2dp Shadow -->
        <item>
            <shape android:shape="rectangle">
                <solid android:color="#000000" />   
            </shape>
        </item>
    
        <!-- White Top color -->
        <item android:bottom="3px" android:right="3px">
            <shape android:shape="rectangle">
                <solid android:color="#FFFFFF" />           
            </shape>
        </item> 
    </layer-list>
    

    Now we can set this shadow view to our TextField using "Background" property

    like this

    res/layout/main.xml

    <EditText android:layout_width="wrap_content" 
                android:id="@+id/txtpin"  
                android:maxLength="4" 
                android:layout_height="37dp" 
                android:gravity="center_horizontal" 
                android:longClickable="false" 
                android:padding="2dp"
    
                android:inputType="textPassword|number" 
                android:password="true" 
                android:background="@drawable/edittext_shadow" 
                android:layout_weight="0.98" 
                android:layout_marginLeft="15dp">
                    <requestFocus></requestFocus>
       </EditText>
    

    and the result screen is like I have posted in question above.

    Thanks to SO, sharing knowledge.

    0 讨论(0)
  • 2020-12-01 04:39

    This works for me..

       <EditText 
           android:layout_width="fill_parent" 
           android:shadowRadius="2"  
           android:shadowColor="#0000ff"
           android:shadowDx="2"
           android:shadowDy="4" 
           android:id="@+id/EditText01" 
           android:layout_height="wrap_content" />
    

    Hope it helps:)

    0 讨论(0)
  • 2020-12-01 04:43

    From Shadow Effect for a Text in Android?, perhaps you'd consider using

    android:shadowColor, 
    android:shadowDx,
    android:shadowDy,
    android:shadowRadius;
    

    Alternatively:

    setShadowLayer()
    
    0 讨论(0)
提交回复
热议问题