Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the text appearance in styles and themes for an Android app

Tags:

I am writing an android app and I am wanting to alter the theme of my app.

I have managed to alter the background colour of the app by using a theme, but I am struggling to change the default text appearance.

This is my styles.xml resource file.

<resources>     <style name="QTheme" parent="android:Theme.Light">         <item name="android:windowBackground">@color/q_green</item>         <item name="android:colorBackground">@color/q_green</item>         <item name="android:textAppearance">@style/QText</item>      </style>      <color name="q_green">#008000</color>     <color name="white">#FFFFFF</color>      <style name="QText" parent="@android:style/TextAppearance.Medium">          <item name="android:textSize">20sp</item>          <item name="android:textColor">@color/white</item>          <item name="android:textStyle">bold</item>         <item name="android:textFont">Verdana</item>     </style> </resources> 

and just to check, this is an example of one of my TextViews I want to use the above style in my layout file.

<TextView     android:id="@+id/txtDevice"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_gravity="center"     android:text="@string/device"  /> 

Can anyone see where I am going wrong?

like image 720
Pippa Rose Smith Avatar asked Nov 16 '12 12:11

Pippa Rose Smith


People also ask

How do you change styles on Android?

Changing the style after creating the view is not supported .. so what you can do is: create a new android xml file of type values. add new theme. add your elements to that theme and their values and save the file.

How can I change my Android app theme?

In Android Studio, open themes. xml (app > res > values > themes > themes.

What is style and theme in Android application?

A style is a collection of attributes that specify the appearance for a single View . A style can specify attributes such as font color, font size, background color, and much more. A theme is a collection of attributes that's applied to an entire app, activity, or view hierarchy—not just an individual view.


2 Answers

Just for completeness, and full credit to Lusprog, this is now my resources file

<resources>     <style name="QTheme" parent="android:Theme.Light">         <item name="android:windowBackground">@color/q_green</item>         <item name="android:colorBackground">@color/q_green</item>         <item name="android:textViewStyle">@style/QText</item>      </style>      <color name="q_green">#008000</color>     <color name="white">#FFFFFF</color>      <style name="QText" parent="@android:style/TextAppearance.Medium">          <item name="android:textSize">20sp</item>          <item name="android:textColor">@color/white</item>          <item name="android:textStyle">bold</item>         <item name="android:typeface">sans</item>     </style> </resources> 

Also thanks to Padma Kumar for the font help.

like image 80
Pippa Rose Smith Avatar answered Oct 06 '22 01:10

Pippa Rose Smith


//remove this line from your styles there is no attribute like this

<item name="android:textFont">Verdana</item> 

//you can give typeface for changing font style

<item name="android:typeface">monospace</item> 

//for settting the styles

<TextView     android:id="@+id/txtDevice"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_gravity="center"     style="@style/QText"     android:text="@string/device"  /> 
like image 28
Padma Kumar Avatar answered Oct 06 '22 01:10

Padma Kumar