Rilcon42
Rilcon42

Reputation: 9765

Setting style in xml

I am trying to set the background and text color in styles.xml and have it apply to my entire application, but it does not apply to each activity at all.

Styles.xml

<resources>

<style name="AppTheme" parent="android:Theme.Light" >
    <item name="android:textColor">#00FF00</item>
    <!--<item name="android:windowNoTitle"> true</item>-->
   <item name="android:windowFullscreen">true</item>
   <item name="android:windowBackground">@color/black</item>
</style>    

</resources>

My Strings.xml includes this line:

<color name="black">#000000</color>

Finally, my AndroidManifest.xml includes:

    <application
    android:icon="@drawable/ic_launcher"
    android:label="Hack the World"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:screenOrientation="landscape" >
    </activity>

Upvotes: 2

Views: 21591

Answers (4)

TouchBoarder
TouchBoarder

Reputation: 6492

To set a background color and text color in styles.xml for the entire application, make sure you have not sett the android:background attr on one of your root elements in your layout files that fills the entire layout.

android:background="#0000FF"

For your colors create a color.xml file in the value folder.

<resources>


  <color name="text_color_green">#00FF00</color>
  <color name="background_color_red">#4BFF0000</color>

</resources>

To set other text colors then the primary text color you must create some custom styles for each widgets in the style.xml file.

-->
<style name="AppBaseTheme" parent="android:Theme.Light">
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
    -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">

    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    <item name="android:windowBackground">@color/background_color_red</item>
    <item name="android:textColor">@color/text_color_green</item>
    <item name="android:windowFullscreen">true</item>

    <!-- Custom style on widgets -->
    <item name="android:editTextStyle">@style/AppTheme_EditTextStyle</item>
    <item name="android:buttonStyle">@style/AppTheme_ButtonStyle</item>


</style>

<!-- Custom Style EditText Widget -->
<style name="AppTheme_EditTextStyle" parent="@android:style/Widget.EditText">
    <item name="android:textColorHint">@color/text_color_green</item>
    <item name="android:textColor">@color/text_color_green</item>
</style>

<!-- Custom Style Button Widget -->
<style name="AppTheme_ButtonStyle" parent="@android:style/Widget.Button">
    <item name="android:textColor">@color/text_color_green</item>
</style>

set the custom theme for the application

   <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <!-- App Activities here-->

</application>

Upvotes: 1

Rahul
Rahul

Reputation: 10625

Make sure that you change the Style for Values v11 or v14 also. v11 is the values of the api version 11, and v14 is the values of the api version 14. So make sure on which Build Target you are compiling your project.

Upvotes: 0

B Kalra
B Kalra

Reputation: 821

Have you saved styles.xml in the /res/values folder of your project? As your style's parent is a predefined android theme,it should be accesible!

Upvotes: 0

Taruni
Taruni

Reputation: 1671

try this. it worked in my case...

<style name="AppTheme" parent="android:Theme.Light">
    <item name="android:textColor">#00FFFF</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:background">#FF00FF</item>

</style>

Upvotes: 2

Related Questions