android - Change Edittext line color when on focus -


i've been trying change baseline color edittext when on focus doesn't seem work..

here's .xml snippet:

<android.support.design.widget.textinputlayout                 android:id="@+id/til_passwordwrapper"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:paddingbottom="@dimen/dimen_10"                 android:paddingleft="@dimen/dimen_10"                 android:paddingright="@dimen/dimen_10"                 android:hint="@string/hint_login_password"                >                 <android.support.v7.widget.appcompatedittext                     android:id="@+id/password"                     android:textsize="17sp"                     android:fontfamily="sans-serif"                     android:textcolor="#000000"                     android:textcursordrawable="#000000"                     android:layout_width="fill_parent"                     android:layout_height="wrap_content"                     android:inputtype="textpassword"                     app:backgroundtint="#000000"                     android:maxlines="1"                     />             </android.support.design.widget.textinputlayout> 

and here styles-v21 file:

<style name="apptheme" parent="apptheme.base">     <item name="colorprimary">@color/colorprimary</item>     <item name="colorprimarydark">@color/colorprimarydark</item>     <item name="coloraccent">@color/colorprimary</item> </style>  <style name="apptheme.base" parent="theme.appcompat.light.noactionbar">     <item name="android:windowcontenttransitions">true</item>     <item name="android:windowentertransition">@android:transition/slide_bottom</item>     <item name="android:windowexittransition">@android:transition/slide_bottom</item>     <item name="android:windowallowentertransitionoverlap">true</item>     <item name="android:windowallowreturntransitionoverlap">true</item>     <item name="android:windowsharedelemententertransition">@android:transition/move</item>     <item name="android:windowsharedelementexittransition">@android:transition/move</item> </style> 

where : - colorprimary = #cd060c (red) - colorprimarydark = #8b181b (darker-red)

i tested on lollipop device , works great. can't same marshamallow device. took @ issue here on s.o see how can solved m , above devices. suggested approach consist of adding these few lines of code in activity class:

passwordwrapper.getedittext().setonfocuschangelistener(new view.onfocuschangelistener(){         @override         public void onfocuschange(view v, boolean hasfocus){             if (hasfocus)             {                 if (build.version.sdk_int >= build.version_codes.lollipop){                     v.setbackgroundtintlist(colorstatelist.valueof(getresources().getcolor(r.color.colorblacktransparent)));                 }             }         }     }); 

on marshmallow device, whenever focus on edittext, keep on having coloraccent i.e red color baseline..i want black..

does has workaround on issue ? thanks

first of don't need use setonfocuschangelistener change underline color of textinputlayout

there android item attribute that, change color when edittext activated.

add attribute in base theme:

<style name="apptheme.base" parent="theme.appcompat.light.noactionbar">      <item name="colorcontrolnormal">#c5c5c5</item>     <item name="colorcontrolactivated">#000000</item>  //black color     <item name="colorcontrolhighlight">#000000</item> </style> 

make sure use theme in activity: manifest

<activity android:name=".youractivity"         android:theme="@style/apptheme.base"/> 

edit

setting colorcontrolhighlight affect navigation drawer selected item color. use:

in res/drawable/drawer.xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android">         <item android:drawable="@color/colorprimary" android:state_checked="true" />         <item android:drawable="@android:color/transparent" /> </selector> 

now in navigation view set background as:

app:itembackground="@drawable/drawer" 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -