Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the color theme of android app?

I’ve been following instructions on how to change the color, but the program produces this error:

06-29 19:20:39.416 7041-7041/com.example.lucerne.adapter_example_2 E/AndroidRuntime: FATAL EXCEPTION: main

    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.

Currently, style.xml looks like below:

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

What is causing the error, and how I can change the colors to something else?

enter image description here

like image 795
Pippi Avatar asked Jun 30 '16 02:06

Pippi


People also ask

How do I change the theme on my phone apps?

If you turn on dark theme in your Android settings, Voice respects that setting unless you change it here. Settings. Under Display Options, tap Theme.

How do I enable Android app themes?

Now, Go to Settings app of your Android phone. Click on the Apps Manage apps Seach. Enter the word "themes" tap on the result uninstall updates. This will enable the themes app and you will stop getting notifications from Google Play.


1 Answers

As the error says, you must extend Theme.AppCompat in your style.

Simple example like this:

<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>

look at the style name at the first style, AppTheme.NoActionBar, it's using AppTheme as its base. Then in the second style, AppTheme.NoActionBar, it's using AppTheme with NoActionBar as its parent.

After you have using AppTheme as the base, you can change the color of your view with your custom style.

like image 113
ישו אוהב אותך Avatar answered Oct 04 '22 09:10

ישו אוהב אותך