2016-06-30 6 views
4

私はcolorを変更する方法の手順を以下してきたが、プログラムはこのエラーを生成します。アンドロイドアプリの色のテーマを変更するには?

6月29日19:20:39.416 7041から7041/com.example.lucerne.adapter_example_2 E/AndroidRuntime:FATAL例外:メイン

Process: com.example.lucerne.adapter_example_2, PID: 7041 
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.lucerne.adapter_example_2/com.example.lucerne.adapter_example_2.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 

は現在、style.xmlは以下のようになります。

<!--<color name="white_opaque">#FFFFFFFF</color>--> 
<!--<color name="pitch_black">#FF000000</color>--> 

<!--<style name="AppTheme" parent="android:Theme.Light">--> 
    <!--<item name="android:background">@color/white_opaque</item>--> 
    <!--<item name="android:windowBackground">@color/white_opaque</item>--> 
    <!--<item name="android:colorBackground">@color/white_opaque</item>--> 

<!--</style>--> 

<!--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> 
</style> 

<!--<style name="AppTheme" parent="@android:style/Theme.Holo.Light">--> 
    <!--<item name="android:actionBarStyle">@style/MyActionBarTheme</item>--> 
<!--</style>--> 
<!--<style name="MyActionBarTheme" parent="@android:style/Widget.Holo.Light.ActionBar">--> 
    <!--<item name="android:background">#FF0000</item>--> 
<!--</style>--> 

エラーの原因は何ですか?また、色を他のものに変更する方法はありますか?エラーが言うように

enter image description here

答えて

4

、あなたはあなたのスタイルでTheme.AppCompatを拡張する必要があります。

このような単純な例:最初のスタイルでスタイル名で

<style name="AppTheme.NoActionBar"> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 
    </style> 

<style name="Theme.SemiTransparent" parent="AppTheme.NoActionBar"> 
    <item name="android:windowIsTranslucent">true</item> 
    <item name="android:windowBackground">@color/colorSemiTransparent</item> 
    <item name="android:windowContentOverlay">@null</item> 
    <item name="android:windowNoTitle">true</item> 
    <item name="android:backgroundDimEnabled">false</item> 
    </style> 

見て、AppTheme.NoActionBar、それはそのベースとしてAppThemeを使用しています。次に、第2のスタイルでは、AppTheme.NoActionBar、それはNoActionBarを親として持つAppThemeを使用しています。

AppThemeをベースとして使用した後は、カスタムスタイルでビューの色を変更できます。

関連する問題