3
I need to change the line color of Edittext programmatically, as I do?
I tried to set an xml in the drawable folder, but it does not change the line color anyway...
3
I need to change the line color of Edittext programmatically, as I do?
I tried to set an xml in the drawable folder, but it does not change the line color anyway...
2
From the version V22.1 of appcompat-v7 it is possible to define a style and attribute it to Edittext through the attribute android:theme
.
In the archive res/style.xml
declare a new style:
<style name="MyEditTextTheme">
<item name="colorControlNormal">#ff0000</item>
<item name="colorControlActivated">#00ff00</item>
<item name="colorControlHighlight">@color/accent_material_light</item>
</style>
Notes:
@color/accent_material_dark
AppCompatActivity
Add the attribute android:theme
to the declaration of Edittext:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
.....
.....
android:theme="@style/MyEditTextTheme"/>
Adapted from here
0
There is no way to change the line color. It is possible to change the background of Edittext and you can put a .PNG
transparent with a colored line underneath, like this for example:
To generate these .PNGs
colorful online you can use this site Android Holo Generator.
However, I recommend downloading the library Materialedittext that implements Edittexts with Material Design and has the feature to change the color of the line programmatically
Browser other questions tagged android android-layout edittext
You are not signed in. Login or sign up in order to post.
I tried to set this in my style, but it displays "Error: No Resource found that Matches the Given name: attr 'colorControlActivated'." for the 3 items
– Morfina
Look at my issue
– ramaral
Have you tested after the issue I made? It answers your question?
– ramaral
Still gives the same error, my api is lvl 8 if I am not mistaken, will be incompatibility?
– Morfina
minSdkVersion="8"
no problem, the problem may be in thetargetSdkVersion
. You should use intargetSdkVersion
always the latest version available, which at this time is the 23. I tested withminSdkVersion="8"
andtargetSdkVersion=23
– ramaral
I just tested with
minSdkVersion="8"
andtargetSdkVersion=8
and it works. I think the only requirements are: V22.1 from appcompat-v7 and Activity inherit from Appcompatactivity.– ramaral
I solved my case by changing the file
colors.xml
in the briefcasevalues
– BrunoAgenor
@Yeah, that’ll do, too. However, in addition to the edittext line color, it will also change the color of other components and this may not be what you want.
– ramaral
Really @ramaral, in my case I wanted to change everything anyway
– BrunoAgenor
Why Ramaral needs to be the latest version available in targetSdkVersion?
– Aline
@Aline, I wanted to say
compileSdkVersion
. It is advisable to always use the latest version of the SDK to compile. The reason is that the latest version, in addition to possible bugs being fixed, adds other features, usually in conjunction with the latest version of appcompat.– ramaral
Hummm when I create a project I chose the minimum API 17...( minSdkVersion 17) and my compileSdkVersion came in the latest android version...I changed the compileSdkVersion to version 23. No problem for an older device??? Leaving compileSdkVersion in the most current version of the device
– Aline
@Aline, no. Always use the latest in
compileSdkVersion
and the corresponding appcompat. What has an impact on older devices isminSdkVersion
. Look at this reply where a small explanation of the differentxxxSdkVersion
. See also this post.– ramaral
Thank you. I get it!
– Aline