游戏服务主题 - oss-licenses

时间:2017-09-18 10:15:22

标签: android open-source android-appcompat

是否有人成功使用新的play-services-oss-licenses库?当尝试按照此处所述使用它时:

https://developers.google.com/android/guides/opensource

我明白了:

  

引起:java.lang.IllegalStateException:        您需要在此活动中使用Theme.AppCompat主题(或后代)。        在android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:354)                                                                                 在android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:323)                                                                                 在android.support.v7.app.AppCompatDelegateImplV9.initWindowDecorActionBar(AppCompatDelegateImplV9.java:175)                                                                                 在android.support.v7.app.AppCompatDelegateImplBase.getSupportActionBar(AppCompatDelegateImplBase.java:145)                                                                                 在android.support.v7.app.AppCompatActivity.getSupportActionBar(AppCompatActivity.java:109)                                                                                 在com.google.android.gms.oss.licenses.OssLicensesMenuActivity.onCreate(未知来源:54)                                                                                 在android.app.Activity.performCreate(Activity.java:6975)                                                                                 在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)                                                                                 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)                                                                                 在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)                                                                                 在android.app.ActivityThread.-wrap11(未知来源:0)                                                                                 在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1593)                                                                                 在android.os.Handler.dispatchMessage(Handler.java:105)                                                                                 在android.os.Looper.loop(Looper.java:164)                                                                                 在android.app.ActivityThread.main(ActivityThread.java:6541)                                                                                 at java.lang.reflect.Method.invoke(Native Method)                                                                                 在com.android.internal.os.Zygote $ MethodAndArgsCaller.run(Zygote.java:240)                                                                                 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

我在我的应用程序的其余部分使用AppCompat - 而不是为此活动设置主题。这是这个库中的一个错误(这是我现在想的) - 或者我做错了什么?

2 个答案:

答案 0 :(得分:2)

您需要为您的案例中的活动设置正确的主题。

在AndroidManifest.xml中添加以下Activity声明:

<activity 
   android:name="com.google.android.gms.oss.licenses.OssLicensesMenuActivity"
   android:theme="@style/Theme.AppCompat.Light.DarkActionBar" />

<activity    
   android:name="com.google.android.gms.oss.licenses.OssLicensesActivity"
   android:theme="@style/Theme.AppCompat.Light.DarkActionBar" />

答案 1 :(得分:0)

如果您还没有发现,插件版本已解决问题

com.google.android.gms:play-services-oss-licenses:16.0.0

您无需在ActionBar上应用主题,因为该插件不再从应用程序中继承样式。

参考:https://developers.google.com/android/guides/releases#july_12_2018