Change background color of edittext in android

前端 未结 10 1612
一个人的身影
一个人的身影 2020-12-25 12:00

If I change the background color of my EditText using the below code, it looks like the box is shrunken and it doesn\'t maintain the ICS theme of a blue bottom

相关标签:
10条回答
  • 2020-12-25 12:31

    The simplest solution I have found is to change the background color programmatically. This does not require dealing with any 9-patch images:

    ((EditText) findViewById(R.id.id_nick_name)).getBackground()
        .setColorFilter(Color.<your-desi‌​red-color>, PorterDuff.Mode.MULTIPLY);
    

    Source: another answer

    0 讨论(0)
  • 2020-12-25 12:36

    What you should do is to create a 9 patch image for edittext and set that image as edit text background. You can create 9 patches using this website

    I am attaching a sample 9 patch image for your reference.Use it as edittext background and you will get an idea.Right click the image and select "save image as". When you save the image dont forget to give its extension as "9.png"

    enter image description here

    0 讨论(0)
  • 2020-12-25 12:36

    For me this code it work So put this code in XML file rounded_edit_text

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape android:shape="rectangle"> <stroke android:width="1dp" android:color="#3498db" /> <solid android:color="#00FFFFFF" /> <padding android:left="5dp" android:top="5dp" android:right="5dp" android:bottom="5dp" > </padding> </shape> </item> </layer-list>

    0 讨论(0)
  • 2020-12-25 12:37

    I create color.xml file, for naming my color name (black, white...)

     <?xml version="1.0" encoding="utf-8"?>
     <resources>
        <color name="white">#ffffff</color>
        <color name="black">#000000</color>
     </resources>
    

    And in your EditText, set color

    <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="asdsadasdasd"
            android:textColor="@color/black"
            android:background="@color/white"
            />
    

    or use style in you style.xml:

    <style name="EditTextStyleWhite" parent="android:style/Widget.EditText">
        <item name="android:textColor">@color/black</item>
        <item name="android:background">@color/white</item>
    </style>
    

    and add ctreated style to EditText:

     <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="asdsadasdasd"
            style="@style/EditTextStyleWhite"
            />
    
    0 讨论(0)
提交回复
热议问题