Add gradient in edit text border in android

强颜欢笑 提交于 2021-02-07 10:25:42

问题


I want to add gradient only to the border of my editText , I can add gradient but it takes the entire background . How can I apply gradient only to the border , and the rest should be transparent?


回答1:


  • Add the edittext in a layout
  • Set gradient background color for that layout
  • Set margin 1dp for edittext.
  • Set white background for edittext

i think now it's displays like your expectation, thank you




回答2:


This one does the trick :)

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <gradient
                android:angle="45"
                android:endColor="#0256FC"
                android:centerColor="#0256FC"
                android:startColor="#FE00B1" />
            <corners android:radius="4dp" />
            <padding
                android:bottom="1dp"
                android:left="1dp"
                android:right="1dp"
                android:top="1dp" />
            <size
                android:width="162dp"
                android:height="44dp" />
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/colorWhite" />
            <corners android:radius="4dp" />
            <size
                android:width="50dp"
                android:height="50dp" />
        </shape>
    </item>
</layer-list>



回答3:


Create your button_border.xml and keep it within drawable.

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

<!-- view border color and width -->
<stroke
    android:width="1dp"
    android:color="@color/white" >
</stroke>

<!-- The radius makes the corners rounded -->
<corners
    android:radius="2dp"   >
</corners>

</shape>

Now set your editText background as follows :

android:background="@drawable/button_border"


来源:https://stackoverflow.com/questions/39830790/add-gradient-in-edit-text-border-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!