setSupportActionBar(toolbar);导致出错的原因

是应为项目的主题样式与toolbar的主题样式与toolbar所在的activity的主题样式不一样所致的,只要将其修改一致即可


<style name="AppTheme" parent="Theme.AppCompat.Light">
    
    <item name="colorPrimary">@color/colorPrimaryitem>
    <item name="colorPrimaryDark">@color/colorPrimaryDarkitem>
    <item name="colorAccent">@color/colorAccentitem>
style>
<declare-styleable name="SlidingPaneLayout">
    <attr name="overhangSize" format="dimension" />
declare-styleable>
<style name="Toolbar.MUHe" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

activity的主题样式:

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

            <category android:name="android.intent.category.LAUNCHER" />
        intent-filter>
    activity>
application>

你可能感兴趣的:(Android)