68

私がしようとしていることは、テーマを使用すると非常に簡単になるはずですが、方法がわかりません。アプリでデフォルトですべてのテキストを白くしたいです。theme.xml でカスタム テーマを作成しました。

<style name="Theme" parent="@android:Theme">
</style>

<style name="TextAppearance.Theme" parent="@android:TextAppearance.Theme">
    <item name="android:textColor">#ffffffff</item>
</style>

アプリケーション全体に設定します。

<application
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@style/Theme">

しかし、ラベルはまだ黒です。何が欠けていますか?

PS: ウィジェットごとに適用されるように、さまざまなテキスト サイズのスタイルを追加で定義するにはどうすればよいですか? そのようなことは正しいですか?

<style name="Theme.smallText">
    <item name="android:textSize">12dp</item>
</style>

アップデート

Android SDK のthemes.xmlを見てみると、テーマのテキスト スタイルを設定する方法が示されています。

<item name="textAppearance">@android:style/TextAppearance</item>

私の場合、この定義で動作するはずです:

<style name="Theme" parent="@android:Theme">
    <item name="android:textAppearance">@style/MyText</item>
</style>

<style name="MyText" parent="@android:style/TextAppearance">
    <item name="android:textColor">#ffffffff</item>
</style>

ただし、まだ機能していません。

これは、この同じ問題に関する別の投稿です。

4

5 に答える 5

68

内部にテキストの色があるManifestの名前を参照する必要があります。現在、空の を参照しているだけです。したがって、theme.xml でこれだけを行います。styleitemstylestyle

<style name="Theme" parent="@android:style/TextAppearance">
    <item name="android:textColor">#ffffffff</item>
</style>

そしてManifest、同じ ( android:theme="@style/Theme")内で参照してください。

編集

テーマ.xml:

<style name="MyTheme" parent="@android:style/TextAppearance">
    <item name="android:textColor">#ffffffff</item>
    <item name="android:textSize">12dp</item>
</style>

マニフェスト:

<application
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@style/MyTheme">

テキストの色とサイズを同じstyle. また、テーマの名前を MyTheme に変更し、Manifest. @android:style/TextAppearanceそして、私は値のために変更しましたparent

于 2012-03-06T23:28:48.230 に答える
24

@android:style/TextAppearanceアプリ全体のテーマの親として使用することはできません。そのため、koopaking3 のソリューションはかなり壊れているように見えます。

カスタム テーマを使用してアプリ内のすべての場所でデフォルトのテキストの色を変更するには、次のようにしてみてください。少なくとも Android 4.0 以降 (API レベル 14 以降) で動作します。

res/values/themes.xml:

<resources>    
    <style name="MyAppTheme" parent="android:Theme.Holo.Light">
        <!-- Change default text colour from dark grey to black -->
        <item name="android:textColor">@android:color/black</item>
    </style>
</resources>

マニフェスト:

<application
    ...
    android:theme="@style/MyAppTheme">

アップデート

上記の欠点は、無効になっているアクション バーのオーバーフロー メニュー項目もグレー表示ではなく、デフォルトの色を使用することです。(もちろん、アプリ内のどこでも無効なメニュー項目を使用していない場合、これは問題にならない可能性があります。)

この質問をすることで学んだように、 drawableを使用して色を定義することをお勧めします。

<item name="android:textColor">@drawable/default_text_color</item>

...別の色をres/drawable/default_text_color.xml指定して:state_enabled="false"

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false" android:color="@android:color/darker_gray"/>
    <item android:color="@android:color/black"/>
</selector>
于 2014-01-22T09:09:26.830 に答える
-2
    <style name="Mytext" parent="@android:style/TextAppearance.Medium"> 
    <item name="android:textSize">20sp</item> 
    <item name="android:textColor">@color/white</item> 
    <item name="android:textStyle">bold</item>
    <item name="android:typeface">sans</item>
</style>

これを試してください...

于 2015-08-24T12:03:28.073 に答える