1

I am trying to change the underline color of Android textfields in Titanium Alloy using a custom theme, but for some reason it doesn't pick up my new colors(s).

Titanium Alloy textfield underline

I have created a theme under project/app/platform/android/res/values/awesome_theme.xml with the following contents:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="awesome" parent="@style/Theme.AppCompat">
        <item name="colorControlNormal">#ff0000</item>
        <item name="colorControlActivated">#00ff00</item>
        <item name="colorControlHighlight">#0000ff</item>
    </style>
</resources>

And I have changed my tiapp.xml file to use the new theme:

<android xmlns:android="http://schemas.android.com/apk/res/android">
    <application android:theme="@style/awesome"/>
</android>

I have cleaned the project, but the text field is still showing up with the default blue underline when I rebuild the project.

What am I doing wrong here?

user6669
  • 155
  • 1
  • 2
  • 10

1 Answers1

0

You have to use a different background image, go to your XML "awesome_theme.xml" and add the custom EditText style

 <style name="EditTextCustomHolo" parent="android:Widget.EditText">
       <item name="android:background">@drawable/apptheme_edit_text_holo_light</item>
       <item name="android:textColor">#ffffff</item>
    </style>

insted of using image drawble file--> apptheme_edit_text_holo_light in that EditText style you can use a drawable resource file which has a stroke , go with that one or this stroke one ,

 <?xml version="1.0" encoding="utf-8"?>
 <item>
    <shape android:shape="rectangle">
        <stroke
            android:width="1dp"
            android:color="@color/white"/>
    </shape>
</item>

then Just do this in your EditText:

<EditText
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   style="@style/EditTextCustomHolo"/>

or

you can change Underline of EditText color specifying it in awesome_theme.xml. add the following tag under your style Theme.AppCompat.

<item name="android:textColorSecondary">@color/primary_text_color</item>

Note : android:textColorSecondary is used to determine the color of the back arrow and DrawerLayout hamburger icon in the ActionBar, too soo careful

Charuක
  • 12,953
  • 5
  • 50
  • 88
  • "go to your XML "styles.xml"". I don't have that file anywhere in my project? – user6669 Dec 17 '16 at 13:33
  • res>values>styles if you dont have a one use the one you have that you add themes see here-> http://carlos-r-mendoza.github.io/img/android-studio-app-with-no-title-bar/change-theme-sytlesxml-file.jpg – Charuක Dec 17 '16 at 13:35
  • Is this answer actually based on my code. It reads like it's copied from somewhere else the way it is written making it pretty confusing to me to say the least. Can you explain why what I have doesn't work? – user6669 Dec 17 '16 at 13:41
  • cuz you dont have @color/primary_text_color in your tag and that will do the job for you, I explained the problem of using that as well , if you want only the answer i think i wasted my time , here i have mentioned 3 different ways to achieve that – Charuක Dec 17 '16 at 13:45
  • When I add `android:textColorSecondary` to my awesome_theme.xml file it doesn't compile anymore. "[ERROR] : Failed to package application: [ERROR] : [ERROR] : Failed to generate resource table for split '' [ERROR] : path/to/project/build\android\res\values\awesome_theme.xml:7: error: Error: No resource found that matches the given name (at 'android:textColorSecondary' with value '@color/primary_text_color'). " – user6669 Dec 17 '16 at 14:04
  • use a color you have for the value res>values>color.xml use a color you have , if you dont have a one create a one -- > http://stackoverflow.com/questions/3769762/android-color-xml-resource-file – Charuක Dec 17 '16 at 14:06
  • what your error says is : you dont have a resource xml with the name of colour or inside that xml you dont have a primary_text_color value – Charuක Dec 17 '16 at 14:09