What I'm trying should be quite easy with themes, but I can't find out how to: I want all text to be white by default in my app. I created a custom theme in theme.xml:
<style name="Theme" parent="@android:Theme"> </style> <style name="TextAppearance.Theme" parent="@android:TextAppearance.Theme"> <item name="android:textColor">#ffffffff</item> </style>
and set it for the whole application:
<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/Theme">
But labels are still black. What's missing?
PS: How can I additionally define styles for different text sizes, to be applied per widget? Is something like that correct?
<style name="Theme.smallText"> <item name="android:textSize">12dp</item> </style>
update
I took a look at themes.xml in Android SDK, it shows how to set the text style for a theme:
<item name="textAppearance">@android:style/TextAppearance</item>
In my case it should work with this definition:
<style name="Theme" parent="@android:Theme"> <item name="android:textAppearance">@style/MyText</item> </style> <style name="MyText" parent="@android:style/TextAppearance"> <item name="android:textColor">#ffffffff</item> </style>
However, it is still not working.
Here's another post about this same issue.
Go to Format > Font > Font. + D to open the Font dialog box. Select the arrow next to Font color, and then choose a color. Select Default and then select Yes to apply the change to all new documents based on the template.
1. Using the theme object. You can create a material UI theme object to change the default styling of the typography. import { createTheme } from '@mui/material/styles'; import { green } from '@mui/material/colors'; const theme = createTheme(theme, { typography: { body1: { color: 'red' }, h1: { color: theme.
In your Manifest
you need to reference the name of the style
that has the text color item
inside it. Right now you are just referencing an empty style
. So in your theme.xml do only this style
:
<style name="Theme" parent="@android:style/TextAppearance"> <item name="android:textColor">#ffffffff</item> </style>
And keep you reference to in the Manifest
the same (android:theme="@style/Theme"
)
EDIT:
theme.xml:
<style name="MyTheme" parent="@android:style/TextAppearance"> <item name="android:textColor">#ffffffff</item> <item name="android:textSize">12dp</item> </style>
Manifest:
<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/MyTheme">
Notice I combine the text color and size into the same style
. Also, I changed the name of the theme to MyTheme and am now referencing that in the Manifest
. And I changed to @android:style/TextAppearance
for the parent
value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With