开发者

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 ?


Try:

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


Try using this:

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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜