Ich habe einige Stilressourcen definiert, die TextAppearance mit einem definierten TextColor enthalten. Ich verwende dann die Stile auf einige TextViews und Buttons. Alle Stile kommen mit dem TextView, aber nicht mit dem Button. Aus irgendeinem Grund wird das TextColor-Attribut nicht angezeigt. Ist das ein Fehler, oder fehlt mir bei dem Button etwas? HierTextColor definiert im Stil, der auf TextView angewendet wird, aber nicht Button?
ist die Stildefinition:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="TestApp">
</style>
<!-- Text Appearances -->
<style name="TestApp.TextAppearance">
<item name="android:typeface">sans</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">16px</item>
<item name="android:textColor">#6666FF</item>
</style>
<!-- Widget Styles -->
<style name="TestApp.Widget">
<item name="android:layout_margin">3sp</item>
</style>
<style name="TestApp.Widget.Label">
<item name="android:textAppearance">@style/TestApp.TextAppearance</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="TestApp.Widget.Switch">
<item name="android:textAppearance">@style/TestApp.TextAppearance</item>
<item name="android:layout_width">100px</item>
<item name="android:layout_height">100px</item>
</style>
</resources>
und hier ist das Layout, in dem ich versuche, sie anzuwenden:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
style="@style/TestApp.Widget.Label"
android:text="This is my label." />
<TextView
style="@style/TestApp.Widget.Label"
android:text="This is my disabled label."
android:enabled="false" />
<Button
style="@style/TestApp.Widget.Switch"
android:text="This is my switch." />
<Button
style="@style/TestApp.Widget.Switch"
android:text="This is my disabled switch."
android:enabled="false" />
</LinearLayout>
Ich hatte das genaue Problem und löste das überschreiben von TextColor. Es scheint, dass Schaltflächen das textAppearance-Attribut ignorieren. –