2017-03-14 2 views
1

Android Studio에서 테스트 용으로 빈 프로젝트를 만들고 value-v21 폴더를 추가합니다.value-v21 폴더에서 스타일을 사용하는 방법은 무엇입니까?

java.lang.RuntimeException: Unable to start activity ComponentInfo{ru.korshun.testapp/ru.korshun.testapp.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 
               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) 
               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
               at android.app.ActivityThread.-wrap11(ActivityThread.java) 
               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
               at android.os.Handler.dispatchMessage(Handler.java:102) 
               at android.os.Looper.loop(Looper.java:148) 
               at android.app.ActivityThread.main(ActivityThread.java:5417) 
               at java.lang.reflect.Method.invoke(Native Method) 
               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
               Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 
               at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:355) 
               at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:324) 
               at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:285) 
               at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
               at ru.korshun.testapp.MainActivity.onCreate(MainActivity.java:11) 
               at android.app.Activity.performCreate(Activity.java:6237) 
               at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)  
               at android.app.ActivityThread.-wrap11(ActivityThread.java)  
               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)  
               at android.os.Handler.dispatchMessage(Handler.java:102)  
               at android.os.Looper.loop(Looper.java:148)  
               at android.app.ActivityThread.main(ActivityThread.java:5417)  
               at java.lang.reflect.Method.invoke(Native Method)  
               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)  
               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)  

이유 : 안드로이드 API 18 에뮬레이터는 API 23에 오류가있어 함께 잘 작동?

내 값 \ styles.xml :

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 

값-V21의 \의 styles.xml :

<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar"> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 

매니페스트 :

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:roundIcon="@mipmap/ic_launcher_round" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity android:name=".MainActivity"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN"/> 
      <category android:name="android.intent.category.LAUNCHER"/> 
     </intent-filter> 
    </activity> 
</application> 

고마워요!

+1

android:theme="@style/AppTheme" 

을 변경 –

답변

0

이 활동과 함께 Theme.AppCompat 테마 (또는 자손)를 사용해야합니다. 재료 테마와 함께 사용할 수 없습니다 당신이 AppCompactActivity을 사용한이

android:theme="@style/Theme.AppCompat"