[英]What is the default text color for Theme.AppCompat.Light.DarkActionBar?
[英]How to change textview default color (Theme.AppCompat.Light.DarkActionBar)
我試圖了解Android的主題和樣式系統,並且基本上試圖做最簡單的事情-更改TextView文本的默認顏色。
根據TextView的源代碼,默認樣式為:
<item name="textViewStyle">@style/Widget.TextView</item>
觀察這種風格,我發現以下內容:
<style name="Widget.TextView">
<item name="textAppearance">?attr/textAppearanceSmall</item>
....
</style>
似乎默認的textAppearance設置為textAppearanceSmall(從主題開始)。
我在themes.xml中查找了所引用的textAppearanceSmall
並找到了以下內容:
<item name="textAppearanceSmall">@style/TextAppearance.Small</item>
啊哈-它引用了這個TextAppearance.Small:
<style name="TextAppearance.Small">
<item name="textSize">14sp</item>
<item name="textColor">?textColorSecondary</item>
</style>
好吧,我們到某個地方-也許嗎? 默認情況下,TextView使用顏色“ textColorSecondary”。
第一個直接的問題:為什么引用這么奇怪? (問號,但不喜歡'?attr / textColorSecondary')?
我回到themes.xml文件並發現以下內容:
<item name="textColorSecondary">@color/secondary_text_dark</item>
在這一點上,我很確定自己必須在自定義AppTheme中重寫textColorSecondary
,如下所示:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColorPrimary">#00CC00</item>
</style>
這當然是行不通的...問題是-為什么?
順便說一句:我正在查看的所有文件(theme.xml和styles.xml)都位於我的Android SDK目錄中:
C:\AndroidSDK\platforms\android-26\data\res\values
嘗試這個:
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:textColor">@color/white</item>
</style>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.