mohammad
mohammad

Reputation: 41

Failed to find style 'navigationViewStyle' in current theme

I used below code for add DrawerLayout but in design view give me following render problem. I can't see my DrawerLayout.

Failed to find style '**navigationViewStyle**' in current theme

This is my code

<?xml version="1.0" encoding="utf-8"?>
<!-- Use DrawerLayout as root container for activity -->
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <!-- Layout to contain contents of main body of screen (drawer will slide over this) -->
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!-- Container for contents of drawer - use NavigationView to make configuration easier -->
    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true" />

</android.support.v4.widget.DrawerLayout>

My gradle file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.0"
    defaultConfig {
        applicationId "com.example.mohammadkhalili.kelaket"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:28.+'
    compile 'com.android.support.constraint:constraint-layout:1.+'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:recyclerview-v7:28.+'
    compile 'com.squareup.okhttp3:okhttp:3.11.0'
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'junit:junit:4.12'
    compile 'com.github.bumptech.glide:glide:3.8.0'
    compile 'de.hdodenhof:circleimageview:1.1.0'
    compile 'com.android.support:design:28.+'
    compile 'com.android.support:support-v4:28.+'
    compile 'com.android.support:cardview-v7:26.0.0-alpha1'
}

Manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.mohammadkhalili.kelaket" >

    <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/Theme.AppCompat.Light.NoActionBar"

        >
        <activity android:name=".Splash" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>



        <activity android:name=".loginpackage.RegisterActivity"/>
        <activity android:name=".loginpackage.ForgetPassActivity" />
        <activity android:name=".mainfilmpage.MainListFilmActivity" />
        <activity android:name=".mainfilmpage.MainFilmActivity" />
        <activity android:name=".loginpackage.login"/>


    </application>

</manifest>

Upvotes: 3

Views: 2937

Answers (3)

Pouria Hemi
Pouria Hemi

Reputation: 735

This problem is a bug in version 28. The only solution is to use version 27 for compileSdkVersion.

To do that, you should use:

dependencies {
        implementation 'com.android.support:appcompat-v7:27.1.1'
        implementation 'com.android.support:cardview-v7:27.1.1'
        implementation 'com.android.support:design:27.1.1'
}

and in build.gradle:

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.your app name"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        lintOptions {
            checkReleaseBuilds false
            abortOnError false
        }
        aaptOptions{
            cruncherEnabled = false
        }
    }
    buildTypes {
        release {

        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

    }
}

Upvotes: 5

ʍѳђઽ૯ท
ʍѳђઽ૯ท

Reputation: 16976

Failed to find style 'navigationViewStyle' in current theme

Hope it isn't late to answer but this is-was a bug in v28 and it has been discussed for many times by now. It always caused the Android Studio Preview not showing the layout and etc.

Solution: The best solution is using stable versions like 27.1.1 or updating to the latest canary version of Android Studio. However, since you were using 28.+, it might choose the wrong version and it is not recommended to use dependencies like you used by adding + after specifying the version.

There is another solution which only needs this piece of code inside Build.gradle:

configurations.all {
        resolutionStrategy.eachDependency { DependencyResolveDetails details ->
            def requested = details.requested
            if (requested.group == "com.android.support") {
                if (!requested.name.startsWith("multidex")) {
                    details.useVersion "27.1.1"
                }
            }
        }
    }

This is actually a bypass to use v27.1.1 API without being need to changing the current build.gradle dependencies.

Also, the version of CardView should be the same as the support library version:

compile 'com.android.support:cardview-v7:26.0.0-alpha1'

Change it to v28 or whatever Support library is.

Upvotes: 0

Mohamed Mohaideen AH
Mohamed Mohaideen AH

Reputation: 2545

Add this line to your theme

<item name="navigationViewStyle">@style/Widget.Design.NavigationView</item>

This will help to rendering navigation view in layout.

Edited

Try with stable android library version number. Something like below

implementation 'com.android.support:appcompat-v7:28.0.0-rc01'

Upvotes: 2

Related Questions