Ahmed
Ahmed

Reputation: 15039

TextView style in dialog, can not see text in froyo but can see in ics

I have a dialog box that I create to display messages in android. It basically contains a text view in a scrollview like this

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent">



        <TextView 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:id="@+id/about_msg" 
            android:text="@string/about_msg"
            android:autoLink="web"
            android:padding="10dip"
            style="@style/DialogTextSmall" />

</ScrollView>

As you can see I have applied a style to TextView the style looks like this

<style name="DialogTextSmall">
    <item name="android:textSize">@dimen/text_size_small</item>        
</style>

The application theme set is like this

    <style name="AppTheme"  parent="android:Theme.Light">    

The Problem:

On ICS api-15 it shows fine black text on white background of TextView.

The problem is When I show dialogbox in Froyo its the text does'nt seem to show even though it seems to have taken space - My guess is the color of text is same as background (greyish black)

I know I can quick fix by hard-coding black background and white text, but Is it not possible to have the default colors of platform for the text color and background of the TextView to appear, without me having to hardcode them ?

Upvotes: 2

Views: 1033

Answers (2)

Ahmed
Ahmed

Reputation: 15039

Inheritance from Textview style did not really help. It is a little quirky problem and here is one way to do it

http://blog.andromo.com/2011/fixing-text-colours-on-an-alertdialog-when-using-theme-light/

In my case I did it another way

Solved it for theme I inherited it from default android theme

<style name="Theme" parent="android:Theme"></style>   
<style name="Theme.AppTheme" parent="@android:style/Theme.Light"/>

and

<style name="DialogTextSmall">
    <item name="android:textSize">@dimen/text_size_small</item>  
    <item name="android:textColor">@android:color/white</item>              
</style>

This way for all platforms , froyo, gingerbread and above, the dialog boxes are black and text is white on them

Upvotes: 1

James McCracken
James McCracken

Reputation: 15766

You can inherit a parent style and then only change the values you want to change. Try changing your XML to this:

<style name="DialogTextSmall" parent="@android:style/Widget.TextView>
    <item name="android:textSize">@dimen/text_size_small</item>        
</style>

The list of styles you can inherit can be found in the AOSP source on Github here.

EIDT:

By default text views have black text and transparent background, so you will need to set one or the other if the background behind the text view (which, again, is transparent) is black.

Upvotes: 1

Related Questions