-1

I tried change a color by use a Material Design method. But after this, when I want to run my application it's stopped work. When I click app icon to run this one, I see this app for circa 1 second only. I see that colors were changed but this application stops work properly. I don't know where is a problem because I use instructions on official Android's website.

Could someone help me to resolve this problem?

Below is my code:

Styles.xml:

 <!-- Base application theme. -->
    <style name="AppTheme" parent="android:Theme.Material">
        <!-- Customize your theme here. -->
        <item name="android:colorPrimary">@color/primaryColor</item>
        <item name="android:colorPrimaryDark">@color/colorprimarydark</item>
        <item name="android:windowBackground">@color/windowbackground</item>
        <item name="android:textColorPrimary">@color/textcolorprimary</item>
    </style>

Colors.xml:

<color name="primaryColor">#FF9800</color>
<color name="colorprimarydark">#FF3F00</color>
<color name="windowbackground">#BDBDBD</color>
<color name="textcolorprimary">#039BE5</color>

Activity.xml:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.example.karol.material_test.MainActivity">

    <TextView
        android:text="Hello World!"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</RelativeLayout>

Logcat:

01-20 21:27:12.120 28957-28957/com.example.karol.material_test E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                 Process: com.example.karol.material_test, PID: 28957
                                                                                 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.karol.material_test/com.example.karol.material_test.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
                                                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2406)
                                                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2466)
                                                                                     at android.app.ActivityThread.access$1200(ActivityThread.java:152)
                                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341)
                                                                                     at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                     at android.os.Looper.loop(Looper.java:135)
                                                                                     at android.app.ActivityThread.main(ActivityThread.java:5538)
                                                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                                                     at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
                                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
                                                                                  Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
                                                                                     at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:151)
                                                                                     at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138)
                                                                                     at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
                                                                                     at com.example.karol.material_test.MainActivity.onCreate(MainActivity.java:12)
                                                                                     at android.app.Activity.performCreate(Activity.java:6013)
                                                                                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
                                                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2359)
                                                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2466) 
                                                                                     at android.app.ActivityThread.access$1200(ActivityThread.java:152) 
                                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341) 
                                                                                     at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                     at android.os.Looper.loop(Looper.java:135) 
                                                                                     at android.app.ActivityThread.main(ActivityThread.java:5538) 
                                                                                     at java.lang.reflect.Method.invoke(Native Method) 
                                                                                     at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960) 
                                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
01-20 21:27:12.510 28957-28957/com.example.karol.material_test I/Process: Sending signal. PID: 28957 SIG: 9
gryzek
  • 537
  • 9
  • 25

1 Answers1

0

You need to use a Theme.AppCompat theme (or descendant) with this activity.

Instead of: android:Theme.Material

Check this:

https://stackoverflow.com/a/21815015/4409113

And just use AppCompat in your styles or AppCompatActivity in the Java codes.

Community
  • 1
  • 1
ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108