2011-11-09 24 views
6

我想將我的主題中的文字外觀設置爲TextAppearnance.Large。 下面是我在做什麼,我styles.xml(我的應用程序指向這個主題在我的清單)主題中的文字外觀

<style name="myTheme" parent="android:Theme.NoTitleBar.Fullscreen"> 
<item name="android:textAppearance">@android:style/TextAppearance.Large</item> 
</style> 

問題: 仍顯示我的文字小。

問題(S):

  • 我在做什麼錯在試圖在我的活動使用預定義的TextAppearance?即如何正確指定此TextAppearance?
  • TextAppearance.Large/Medium/Small的TextSizes在哪裏定義?
+0

看一下前面提到的這個問題,在stackoverflow上。 http://stackoverflow.com/questions/1726897/how-to-set-text-appearance-in-android-manifest-file可能會有所幫助。 –

+0

是的,我看到那篇文章,但在item標籤中使用'?android:attr/TextAppearance.Large'會產生一個編譯錯誤。 – celoftis

+0

我的答案在這裏可能有所幫助:http://stackoverflow.com/a/8380153/102703 –

回答

-1

主題和樣式在您的環境中sdk實現的themes.xml和styles.xml文件中定義(對於不同的android版本或sdk級別,它們是不同的)。

在您的計算機上搜索themes.xml(例如,您可能會在Windows 32位計算機上的「program files/android」文件夾中找到它的多個實例)。

this post解釋瞭如何自定義這些屬性。

你也可以設置明確的尺寸在你的XML佈局文件屬性,通過修改TextView tag屬性:

<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="15sp is the 'normal' size." 
    android:textSize="15sp" 
    /> 

this post說明如何自定義Android的字體(包括fontType,FONTCOLOR,陰影,粗體,斜體)直接在xml佈局文件中。

+0

使用樣式是避免xml代碼重複並獲得所有textview的一致行爲並能夠指定textView樣式的好方法,如TextViewTitle ,TextViewNormal ...等等。 –

+1

我不討論一種方法優於另一種方法,只是回答提出的問題。 :) –

5

首先,聲明屬性作爲

<item name="android:textAppearance">?android:attr/textAppearanceLarge</item> 

但聲明文本外觀或文本顏色主題隻影響已經完全沒有風格或屬性的任何地方,包括系統定義的那些文字。如果添加

<TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Medium Text" /> 

甚至沒有android:textAppearance="?android:attr/textAppearanceMedium"行的Eclipse拋出,它會被這個主題的影響,但按鈕等,永遠不會。