2011-08-24 38 views
6

我閱讀文檔,它說這樣「一種風格可以指定屬性,如高度,填充,字體顏色,字體大小,背景顏色,以及更多」現在我的問題是什麼是「更多」。這是否意味着我可以爲android:src定義不同的屬性? 就是這樣的背景圖像的主題和風格屬性

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

我嘗試background屬性,它工作正常

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

但不SRC屬性:-(。

我該怎麼辦錯了嗎?

+0

我也需要這個! – CelinHC

+0

你找到了什麼? – Lukap

回答

6

嘗試

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

在我的測試中,根據這篇文章(How to change a TextView's style at runtime),在樣式中設置背景圖片不起作用。

嘗試在你的Java類這樣的事情,如果你編程設置樣式:

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

或像這樣的東西,如果你設置樣式在您的佈局:

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

你不能直接使用drawable。在res/drawable中創建一個xml文件。在你的style.xml中引用它。
RES /繪製/ attach.xml

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

RES /價值/ styles.xml

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

我還沒有建立^^但這是一般的想法。