I want to define a default text color for my android app.
I have a base activity class, that all activities are extended from it and I thought this might be a good place to define the colors.
If not what is a better solution? Maybe styles?
Trouble is this, all is new to me, so feel free to advise me and provide code snippets and explanations as well.
This is what my base class looks like. As you can see it's pretty empty
package com.ccslocal.mobile.quiz.jls; import android.app.Activity; import android.os.Bundle; public class BaseActivity extends Activity { //set up app preferences here }
Open your device's Settings app . Text and display. Select Color correction. Turn on Use color correction.
As was mentioned in denis.solonenko's answer, the correct approach would be to modify your theme.
Where you define your theme (in your themes.xml or styles.xml file), you'll want to add something like this:
<style name="AppTheme" parent="@style/Theme.AppCompat.Light"> ... <item name="android:textColor">#FF00FF</item> ... </style>
Then make sure that the theme is applied to your Activity or Application in the manifest:
<application ... android:theme="@style/AppTheme" .... >
You can also define:
(Source TextColor vs TextColorPrimary vs TextColorSecondary)
Keep in mind that many other things may override these predefined colors, such as applied styles or definitions in different resource folders.
See here for a full list of theme items: https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/values/themes.xml
Create a custom theme for your app. Take look at the official guide.
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