Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set text color in android app for all text?

Tags:

android

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 } 
like image 678
jamesc Avatar asked Aug 03 '11 04:08

jamesc


People also ask

How do you change the color of text on Android apps?

Open your device's Settings app . Text and display. Select Color correction. Turn on Use color correction.


2 Answers

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:

  • textColor - The default text color of any given view
  • textColorPrimary - The default text color for enabled buttons and Large Textviews
  • textColorSecondary - The default text color for Medium and Small Textviews
  • textColorTertiary - ?

(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

like image 122
TheIT Avatar answered Oct 10 '22 02:10

TheIT


Create a custom theme for your app. Take look at the official guide.

like image 40
denis.solonenko Avatar answered Oct 10 '22 01:10

denis.solonenko