I am starting a new project, so the project is more or less "empty". I just added a MainActivity, with a MainActivityFragment. I haven't added any code at all to them.
Now, I edit the styles.xml so it looks like this:
<resources>
<!-- Base application theme. -->
<style name="MyTheme" parent="@android:style/Theme.Material.Light.DarkActionBar">
<item name="android:windowNoTitle">true</item>
<!--We will be using the toolbar so no need to show ActionBar-->
<item name="android:windowActionBar">false</item>
<!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette-->
<!-- colorPrimary is used for the default action bar background -->
<item name="android:colorPrimary">#2196F3</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="android:colorPrimaryDark">#1976D2</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="android:colorAccent">#FF4081</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight and colorSwitchThumbNormal. -->
<item name="toolbarStyle">@style/Widget.AppCompat.Toolbar</item>
</style>
</resources>
So, I extend the Material theme as you can see.
I then create a toolbar xml file (mytoolbar.xml), like this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/abc_ic_voice_search_api_mtrl_alpha"/>
</android.support.v7.widget.Toolbar>
And here is the problem:
I can't figure out why. I have done gradle sync, clean, rebuild, restarted IDE (Android Studio 1.2.1.1), nothing works.
Any ideas?
There is a bug in android [pre-lollipop] OS which doesnt allow you to use attr in drawable. Here is the link to bug:
https://code.google.com/p/android/issues/detail?id=26251
Android dev team has released a fix but it works on android L and above. For workaround to this problem, refer to following solution:
How to reference style attributes from a drawable?
Prepend android keyword to it.
?attr/colorPrimary"
becomes
?android:attr/colorPrimary
working fine in android studio 3.0 .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With