8

I read documentation and it says like this "A style can specify properties such as height, padding, font color, font size, background color, and much more" now my question is what is "more". Is that means that I can define different properties for for android:src ? that is something like this

<item name="android:src">@drawable/attachment1</item>

I try background property and it works fine

<item name="android:background">#55FFFFFF</item>

but not src property :-(.

What do I do wrong ?

Lukap
  • 31,523
  • 64
  • 157
  • 244

4 Answers4

6

Try:

<item name="android:background">@drawable/attachment1</item>
Nimantha
  • 6,405
  • 6
  • 28
  • 69
johannes
  • 61
  • 1
  • 2
1

Try using this:

<item name="android:windowBackground">@drawable/imageone</item>
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Shiva
  • 454
  • 5
  • 10
0

In my testing and according to this post (How to change a TextView's style at runtime), setting the background image in the style doesn't work.

Try something like this in your java class if you're setting the style programmatically:

countField.setTextAppearance(getContext(),R.style.theme_id);
countField.setBackgroundResource(R.drawable.attachment1);

Or something like this if you're setting the style in your layouts:

<TextView
  android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="hello world"
    android:layout_gravity="center"
    android:textAppearance="@style/MVTheme.TextAppearance.CalendarMissedCount"
    android:background="@drawable/attachment1 />
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Dave
  • 6,504
  • 4
  • 30
  • 37
-1

You can't use a drawable directly. Make an xml file in the res/drawable. Refer to it in your style.xml.
res/drawable/attach.xml

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/attachment1"
    />

res/values/styles.xml

<item name="android:src">@drawable/attach</item>

I have not built ^^ but this is the general idea.

Johan vdH
  • 364
  • 4
  • 11