I wrote this SSCCE to demonstrate the problem. The emulator is NexusFive but it is customised to use API22.
SSCCE
res/values/colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="primaryColor">#69F0AE</color> <!-- Light ferozi -->
<color name="primaryColorDark">#00E676</color> <!-- Darker Ferozi -->
<color name="accentColor">#F44336</color> <!-- Red 500 -->
</resources>
res/values/styles.xml
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat"></style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="colorPrimary">@color/primaryColor</item>
<item name="colorPrimaryDark">@color/primaryColorDark</item>
<item name="colorAccent">@color/accentColor</item>
</style>
</resources>
res/values-v21/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:colorPrimary">@color/primaryColor</item>
<item name="android:colorPrimaryDark">@color/primaryColorDark</item>
<item name="android:colorAccent">@color/accentColor</item>
</style>
</resources>
activity_main.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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="practice_projects.material_design_google_now_like_searchbox_four.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, 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);
}
}
Try to change your theme to this:
Add the Toolbar to your
activity_main.xml
:And from your
AppCompatActivity
:An
AppCompatActivity
will not recognizeandroid:colorPrimary
. If you are only changing these properties, it is completely unnecessary to create a v21 styles.xml. If you are customizing other properties for v21, then just move your color properties to the base theme and delete them from v21 styles.xml.The parent for Materail Theme must be defined:. For Example: