2
votes

Since 2 days I try to use the material design in a new app (sdk 20-).

I read some tutorials and with this one [http://android-developers.blogspot.fr/2014/10/appcompat-v21-material-design-for-pre.html][1] i've this error :

C:\Users\Maxime\Desktop\MaterialApp\app\src\main\res\values\themes.xml Error:Error retrieving parent for item: No resource found that matches the given name 'android:Theme.AppCompat.Light'. Error:Execution failed for task ':app:processDebugResources'. com.android.ide.common.internal.LoggedErrorException: Failed to run command: C:\Users\Maxime\AppData\Local\Android\android-studio3\sdk\build-tools\21.0.2\aapt.exe package -f --no-crunch -I C:\Users\Maxime\AppData\Local\Android\android-studio3\sdk\platforms\android-21\android.jar -M C:\Users\Maxime\Desktop\MaterialApp\app\build\intermediates\manifests\debug\AndroidManifest.xml -S C:\Users\Maxime\Desktop\MaterialApp\app\build\intermediates\res\debug -A C:\Users\Maxime\Desktop\MaterialApp\app\build\intermediates\assets\debug -m -J C:\Users\Maxime\Desktop\MaterialApp\app\build\generated\source\r\debug -F C:\Users\Maxime\Desktop\MaterialApp\app\build\intermediates\libs\app-debug.ap_ --debug-mode --custom-package com.maxime.myapplication -0 apk --output-text-symbols C:\Users\Maxime\Desktop\MaterialApp\app\build\intermediates\symbols\debug Error Code: 1 Output: C:\Users\Maxime\Desktop\MaterialApp\app\build\intermediates\res\debug\values\values.xml:2411: error: Error retrieving parent for item: No resource found that matches the given name 'android:Theme.AppCompat.Light'.

I add my files that I created to get this :

/res/values/themes.xml

<resources>
<style name="Theme.MyTheme" parent="android:Theme.AppCompat.Light">
    <!-- colorPrimary is used for the default action bar background -->
    <item name="colorPrimary">@color/yellow</item>

<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">@color/blue</item>

<!-- colorAccent is used as the default value for colorControlActivated,
     which is used to tint widgets -->
<item name="colorAccent">@color/green</item>

<!-- You can also set colorControlNormal, colorControlActivated
     colorControlHighlight, and colorSwitchThumbNormal. -->

</style>

/res/layout/activity_home.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.maxime.materialapp.HomeActivity">

<android.support.v7.widget.Toolbar
    layout_height="match_parent"
    layout_width="match_parent"
    android:id="@+id/toolbar"
    minHeight="?attr/actionBarSize"
    background="?attr/colorPrimary" />

/java/package/HomeActivity.java

public class HomeActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.home, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

In this last, setSupportActionBar(toolbar) is not recognize.

And my gradle : `apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.0.2"

    defaultConfig {
        applicationId "com.maxime.myapplication"
        minSdkVersion 19
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}


    dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile "com.android.support:appcompat-v7:21.0.+"
}
3

3 Answers

1
votes

The AppCompat theme is Theme.AppCompat.Light, not android:Theme.AppCompat.Light

0
votes

try changing your styles.xml to this <style name="AppTheme" parent="android:Theme.Material"> and refer to this tutorial https://developer.android.com/training/material/index.html

0
votes

You need to use ActionBarActivity together with setSupportActionBar instead of Activity if you're going to use the support version of the Toolbar (android.support.v7.widget.Toolbar).

Activity.setActionBar(android.widget.Toolbar toolbar) was added in API Level 21 and thus cannot be used with minSdkVersion 19

Also, as mentioned by Ian Lake you must use Theme.AppCompat.Light, not android:Theme.AppCompat.Light