Saif Khan
Saif Khan

Reputation: 309

Why are some of my styles not working with lower APIs?

I have a quick question!

In my styles.xml file, I have

<style name="TextViewStyle" parent="android:Widget.TextView">
    <item name="android:padding">20px</item>
    <item name="android:background">#9cd0e8</item>
    <item name="android:textColor">#254b7c</item>
    <item name="android:textSize">18sp</item>
    <item name="android:textStyle">bold</item>
</style>

And in my activity_main.xml, I have

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:theme="@+styles/TextViewStyle"
    android:text="Sample Text"/>

What I am trying to do is, in my Android application, on a certain activity I plan to place many TextViews with similar properties. Instead of writing these 'properties' every time with each TextView instance, I grouped them together in a style in styles.xml file and set theme of each of my TextViews to that style.

It works fine and does what I want it to do, but only with APIs above 21! My application's supposed to support devices from API level 15 up. Why is my approach not working with lower APIs?

Please help soon. I need to finish this soon.

EDIT

By 'working', I meant that the attributes I set in my style (padding, color, etc.) appear on the TextViews as they should. In lower APIs however, the TextViews appear as if I had not applied any attribute on them. Plain text appears instead of a styled one.

Upvotes: 0

Views: 1982

Answers (1)

Krzysztof Turek
Krzysztof Turek

Reputation: 136

  1. remove parent from your style
  2. remove android:theme from textView, (why there is + sign?)
  3. instead of theme put this into your textView

style="@style/TextViewStyle"

btw, use dp instead of px ;)

Upvotes: 2

Related Questions