Lukap
Lukap

Reputation: 31963

Theme and style properties for background image

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 ?

Upvotes: 8

Views: 12069

Answers (4)

Dave
Dave

Reputation: 6652

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 />

Upvotes: 0

johannes
johannes

Reputation: 61

Try:

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

Upvotes: 6

Shiva
Shiva

Reputation: 454

Try using this:

<item name="android:windowBackground">@drawable/imageone</item>

Upvotes: 1

Johan vdH
Johan vdH

Reputation: 394

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.

Upvotes: -1

Related Questions