0

The problem is - when I define a text color in styles:

<style name="Widget.App.SearcherButton" parent="Widget.AppCompat.Button">
    <item name="android:textAllCaps">false</item>
    <item name="android:textColor">@color/buttontextcolor</item>
</style>

<ToggleButton
    android:layout_width="wrap_content"
    android:layout_height="@dimen/searcherButtonHeight"
    android:background="@drawable/button"
    android:theme="@style/Widget.App.SearcherButton"
    android:textOn="@string/favButtonText"
    android:textOff="@string/favButtonText" />

it won't work - meaning that the ToggleButton will have the default text colo (black). If I however set textColor property directly on a ToggleButton:

<ToggleButton
    android:layout_width="wrap_content"
    android:layout_height="@dimen/searcherButtonHeight"
    android:background="@drawable/button"
    android:textColor="@color/buttontextcolor"
    android:theme="@style/Widget.App.SearcherButton"
    android:textOn="@string/favButtonText"
    android:textOff="@string/favButtonText" />

Then it works. Why is that and how to make it work when declared in styles?

Marek M.
  • 3,799
  • 9
  • 43
  • 93

1 Answers1

1

You need to add the style to the ToggleButton itself not just using 'android:theme=" " '. Something like

<ToggleButton
android:id = "@+id/toggleButton"
...
style = "@style/stylename"/>
Agbede S.
  • 28
  • 4
  • 1
    A style according to developer.android.com is "A style is a collection of properties that specify the look and format for a **View or window.** ". developer.android.com defines themes as ''a style applied to an entire **Activity or application**, rather than an individual View". You could check this [link](https://developer.android.com/guide/topics/ui/themes.html) for more information. Do let me know if you do not get my analogy so I could look for another one. Cheers. – Agbede S. Sep 11 '16 at 07:49
  • This explanation is ok. Thanks! – Marek M. Sep 11 '16 at 07:57