Reputation: 12937
Is it possible to apply an accent color to an particular EditText while others are unaffected ?
i have this :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- EditText on a blue background -->
<style name="BlueBGTextView" parent="@android:style/Widget.Material.Light.EditText">
</style>
<!-- default EditText -->
<style name="AppTheme.EditTextStyle" parent="@android:style/Widget.Material.Light.EditText">
</style>
<!-- default Theme -->
<style name="AppTheme" parent="@android:style/Theme.Material.Light.NoActionBar">
<item name="android:editTextStyle">@style/AppTheme.EditTextStyle</item>
<item name="android:colorAccent">#ff0288d1</item> <!-- use to setup the color of the text selection handles -->
<item name="@attr/BlueBGTextViewStyle">@style/BlueBGTextView</item>
</style>
</resources>
but the problem is that <item name="android:colorAccent">#ff0288d1</item>
is applied globally to all my edits. I would like to apply it only to the
<style name="BlueBGTextView" parent="@android:style/Widget.Material.Light.EditText">
</style>
any idea how i can do this ?
Upvotes: 0
Views: 1641
Reputation: 1375
try this, i have tested it on my system.
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:theme="@style/Edittext" />
declare your theme is styles.xml
<style name="Edittext" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#ed2727</item>
<item name="colorPrimaryDark">#ed2727</item>
<item name="colorAccent">#ed2727</item>
<item name="colorControlNormal">#ed2727</item>
<item name="colorControlActivated">#ed2727</item>
<item name="colorControlHighlight">#ed2727</item>
</style>
reference here
Upvotes: 1
Reputation: 2677
I have used like this hope this can help u
<style name="MyEditTextTheme">
<!-- Used for the bottom line when not selected / focused -->
<item name="colorControlNormal">#9e9e9e</item>
<!-- colorControlActivated & colorControlHighlight use the colorAccent color by default -->
</style>
Now u can apply this theme to particular edittext
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/MyEditTextTheme"/>
Upvotes: 1