Android 在库模块中添加工具栏

Android 在库模块中添加工具栏,android,android-toolbar,illegalstateexception,Android,Android Toolbar,Illegalstateexception,我正在库项目的活动中添加工具栏。在我的库AndroidManifest中,我使用这个主题- <style name="NoobAppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item>

我正在库项目的活动中添加工具栏。在我的库AndroidManifest中,我使用这个主题-

<style name="NoobAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="toolbarStyle">@style/Widget.AppCompat.Toolbar</item>
</style>
我得到以下例外情况-

--------- beginning of crash
10-12 02:54:32.171 28558-28558/noob.com.noobfilechooser E/AndroidRuntime: FATAL EXCEPTION: main
                                                                          Process: noob.com.noobfilechooser, PID: 28558
                                                                          java.lang.RuntimeException: Unable to start activity ComponentInfo{noob.com.noobfilechooser/com.noob.noobfilechooser.NoobFileActivity}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2434)
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494)
                                                                              at android.app.ActivityThread.access$900(ActivityThread.java:153)
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1347)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                              at android.os.Looper.loop(Looper.java:148)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:5451)
                                                                              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: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
                                                                              at android.support.v7.app.AppCompatDelegateImplV9.setSupportActionBar(AppCompatDelegateImplV9.java:199)
                                                                              at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:130)
                                                                              at com.noob.noobfilechooser.NoobFileActivity.onCreate(NoobFileActivity.java:60)
                                                                              at android.app.Activity.performCreate(Activity.java:6323)
                                                                              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2387)
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494) 
                                                                              at android.app.ActivityThread.access$900(ActivityThread.java:153) 
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1347) 
                                                                              at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                              at android.os.Looper.loop(Looper.java:148) 
                                                                              at android.app.ActivityThread.main(ActivityThread.java:5451) 
                                                                              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) 
我试过打电话

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

对异常没有影响。在我的图书馆活动中使用工具栏,我能做些什么吗?

好的,这真的很愚蠢。我在库清单中的应用程序元素中设置了主题,而我应该在活动中设置它

正确的方法

<application
        android:allowBackup="true"
        android:label="@string/app_name"
        android:supportsRtl="true">
        <activity android:theme="@style/NoobAppTheme"
            android:name=".NoobFileActivity">
        </activity>
</application>
<application
        android:allowBackup="true"
        android:label="@string/app_name"
        android:theme="@style/NoobAppTheme"
        android:supportsRtl="true">
        <activity android:name=".NoobFileActivity">
        </activity>
</application>

走错了路

<application
        android:allowBackup="true"
        android:label="@string/app_name"
        android:supportsRtl="true">
        <activity android:theme="@style/NoobAppTheme"
            android:name=".NoobFileActivity">
        </activity>
</application>
<application
        android:allowBackup="true"
        android:label="@string/app_name"
        android:theme="@style/NoobAppTheme"
        android:supportsRtl="true">
        <activity android:name=".NoobFileActivity">
        </activity>
</application>


从您的日志中,此活动已经有一个由窗口装饰提供的操作栏。不要请求Window.FEATURE\u SUPPORT\u ACTION\u工具栏,并在主题中将windowActionBar设置为false以使用工具栏。@zombie我可以读取日志。我可以在我的应用程序模块中更改主题,但我宁愿让我的库的用户决定他们是否希望在应用程序中使用工具栏。这是否有帮助@zombie谢谢您的帮助,但问题已经解决了。(请核对答案):-)