Is an "animation-list" drawable supported in Jetpack Compose? - android
I am converting a layout android app to compose. I have encountered an issue using an "animated-list" from my drawable resources, and I am guessing that this format is just not supported with Compose, at least at this time.
It appears to me that the compiler is generating the resources for the app, but Compose just has no idea how to reference an "animation-list".
For the below, it might be worth noting that I'm using colors as references also like
android:strokeColor="#color/border"
My drawable resource is like this from src\main\res\drawable\garage_door_closing_animation.xml
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="#drawable/garage_door_closing_frame_0" android:duration="200" />
<item android:drawable="#drawable/garage_door_closing_frame_1" android:duration="200" />
<item android:drawable="#drawable/garage_door_closing_frame_2" android:duration="200" />
<item android:drawable="#drawable/garage_door_closing_frame_3" android:duration="200" />
<item android:drawable="#drawable/garage_door_closing_frame_4" android:duration="200" />
<item android:drawable="#drawable/garage_door_closing_frame_5" android:duration="200" />
</animation-list>
where a frame is like this
drawable/garage_door_closing_frame_0
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#drawable/garage_door_action_background"
android:gravity="center" />
<item
android:drawable="#drawable/garage_door_closing_arrow_0"
android:gravity="center" />
</layer-list>
and the two items referenced are like this
drawable/garage_door_action_background
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="200dp"
android:height="200dp"
android:background="#android:color/transparent"
android:viewportWidth="150"
android:viewportHeight="150">
<path
android:name="base"
android:fillColor="#color/border"
android:pathData="M1.046,137.248h147.95v10.091h-147.95z"
android:strokeWidth="1.2144" />
<path
android:name="house_frame"
android:fillColor="#color/border"
android:pathData="M15.002,137.24H1.658V34.66L74.647,1.576 148.392,34.408V137.324l-12.333,-0.085v0,-94.425L75.53,16.619 74.32,16.653 15.002,42.815Z"
android:strokeWidth="1.21061"
android:strokeColor="#color/border"
android:strokeLineCap="butt"
android:strokeLineJoin="miter" />
<path
android:name="door_frame"
android:fillColor="#color/border"
android:pathData="m30.713,54.916c-0.657,1.202 -0.137,2.713 -0.303,4.042 0,25.895 0,51.789 0,77.683 0.333,1.417 2.134,0.657 3.169,0.848 3.743,-0.041 7.515,0.083 11.24,-0.06 1.213,-0.459 0.479,-2.112 0.68,-3.108 0,-21.921 0,-43.843 0,-65.764 20.031,0 40.063,0 60.094,0 0,22.695 0,45.39 0,68.085 0.333,1.417 2.134,0.657 3.169,0.848 3.743,-0.041 7.515,0.083 11.24,-0.06 1.213,-0.459 0.48,-2.112 0.68,-3.108 0,-26.252 0,-52.503 0,-78.755 -0.332,-1.417 -2.133,-0.657 -3.169,-0.848 -28.752,0 -57.504,0 -86.255,0 -0.182,0.066 -0.363,0.132 -0.545,0.198z"
android:strokeWidth="0.178596"
android:strokeColor="#color/border" />
<path
android:name="handle"
android:fillColor="#color/border"
android:pathData="m74.639,75.938c-5.439,-1.138 -7.655,-7.121 -4.097,-11.059 2.289,-2.534 5.848,-3.205 8.934,-1.686 4.231,2.083 5.19,7.399 1.926,10.681 -1.654,1.663 -4.512,2.536 -6.763,2.064z"
android:strokeWidth="0.208623" />
<path
android:name="open_door"
android:fillColor="#color/border"
android:pathData="M45.48,77.399h60.315v59.84h-60.315z" />
</vector>
and
drawable/garage_door_closing_arrow_0
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="200dp"
android:height="200dp"
android:background="#android:color/transparent"
android:viewportWidth="150"
android:viewportHeight="150">
<path
android:fillColor="#00ff00"
android:pathData="m30.053,9.133 l45.75,38.75 45.75,-38.75h-16l-29.5,24.5 -30.5,-24.5z"
android:strokeWidth="1"
android:strokeColor="#ffffff"
android:strokeLineCap="butt"
android:strokeLineJoin="miter" />
</vector>
My composable which tries to load this is below, and this compiles but throws a runtime error
#Composable
fun GarageIndicator () {
val image = AnimatedImageVector.animatedVectorResource(R.drawable.garage_door_closing_animation)
and the error is
FATAL EXCEPTION: main
Process: com.lusion.sgauto, PID: 17467
android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:226)
at android.content.res.Resources.getValue(Resources.java:1437)
at androidx.compose.ui.res.VectorResources_androidKt.vectorResource(VectorResources.android.kt:65)
at androidx.compose.animation.graphics.vector.compat.XmlAnimatedVectorParser_androidKt.parseAnimatedImageVector(XmlAnimatedVectorParser.android.kt:74)
at androidx.compose.animation.graphics.res.AnimatedVectorResources_androidKt.loadAnimatedVectorResource(AnimatedVectorResources.android.kt:61)
at androidx.compose.animation.graphics.res.AnimatedVectorResources_androidKt.animatedVectorResource(AnimatedVectorResources.android.kt:48)
at com.lusion.sglibrary.MainActivity.GarageIndicator(MainActivity.kt:1497)
at com.lusion.sglibrary.MainActivity$onResume$1.invoke(MainActivity.kt:349)
at com.lusion.sglibrary.MainActivity$onResume$1.invoke(MainActivity.kt:348)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.ui.platform.ComposeView.Content(ComposeView.android.kt:428)
at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated$1.invoke(ComposeView.android.kt:252)
at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated$1.invoke(ComposeView.android.kt:251)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
at androidx.compose.ui.platform.CompositionLocalsKt.ProvideCommonCompositionLocals(CompositionLocals.kt:177)
at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$ProvideAndroidCompositionLocals$3.invoke(AndroidCompositionLocals.android.kt:123)
at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$ProvideAndroidCompositionLocals$3.invoke(AndroidCompositionLocals.android.kt:122)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt.ProvideAndroidCompositionLocals(AndroidCompositionLocals.android.kt:114)
at androidx.compose.ui.platform.WrappedComposition$setContent$1$1$3.invoke(Wrapper.android.kt:157)
at androidx.compose.ui.platform.WrappedComposition$setContent$1$1$3.invoke(Wrapper.android.kt:156)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(Wrapper.android.kt:156)
at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(Wrapper.android.kt:140)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.ActualJvm_jvmKt.invokeComposable(ActualJvm.jvm.kt:78)
at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:3314)
at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:3304)
at androidx.compose.runtime.SnapshotStateKt__DerivedStateKt.observeDerivedStateRecalculations(DerivedState.kt:341)
at androidx.compose.runtime.SnapshotStateKt.observeDerivedStateRecalculations(Unknown Source:1)
and, last, for what it is worth, I have tried leveraging all the latest compose libs in gradle as
implementation "androidx.compose.compiler:compiler:1.4.0-alpha02"
implementation "androidx.compose.animation:animation:1.3.2"
implementation "androidx.compose.animation:animation-graphics:1.3.2"
implementation "androidx.compose.foundation:foundation-layout:1.4.0-alpha04"
implementation "androidx.compose.foundation:foundation:1.4.0-alpha04"
implementation "androidx.compose.material:material:1.4.0-alpha04"
implementation "androidx.compose.material3:material3:1.1.0-alpha04"
implementation "androidx.compose.runtime:runtime:1.4.0-alpha04"
implementation "androidx.compose.runtime:runtime-livedata:1.4.0-alpha04"
implementation "androidx.compose.ui:ui:1.4.0-alpha04"
implementation "androidx.compose.ui:ui-tooling:1.4.0-alpha04"
I am hoping I can use the current layout resource animation-list and not have to figure out how to convert it to an "animated-vector" resource.
build.gradle Configure the useSupportLibrary property:
android {
compileSdk 31
defaultConfig {
applicationId "com.your.package.xxxx"
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"
vectorDrawables {
useSupportLibrary true
}
}
}
display:
val animationDrawable = AnimationDrawable()
//add your images in animationDrawable by giving information of duration etc like you gave in xml file..
Image(
painter = rememberDrawablePainter(animationBlast),
contentDescription = null,
modifier = Modifier.wrapContentSize(),
contentScale = ContentScale.Crop
)
animationDrawable?.start()
Related
Resource not found exception for ShapeableImageView using vector?
I am using ShapeableImageView in my XML as <com.google.android.material.imageview.ShapeableImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="#drawable/ic_unread_msg" /> I am getting Resource not found exception when I run the app on OS 5 and 6 Caused by android.content.res.Resources$NotFoundException: File res/drawable/ic_unread_msg.xml from drawable resource ID #0x7f0700f7 at android.content.res.Resources.loadDrawableForCookie(Resources.java:2850) at android.content.res.Resources.loadDrawable(Resources.java:2732) at android.content.res.TypedArray.getDrawable(TypedArray.java:870) at android.widget.ImageView.<init>(ImageView.java:152) at android.widget.ImageView.<init>(ImageView.java:140) at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java:74) at com.google.android.material.imageview.ShapeableImageView.<init>(ShapeableImageView.java:96) at com.google.android.material.imageview.ShapeableImageView.<init>(ShapeableImageView.java:92) at java.lang.reflect.Constructor.newInstance(Constructor.java) Caused by android.content.res.Resources$NotFoundException: File res/drawable/$ic_unread_msg__0.xml from color state list resource ID #0x7f07000b at android.content.res.Resources.loadColorStateListForCookie(Resources.java:2960) at android.content.res.Resources.loadColorStateList(Resources.java:2909) at android.content.res.TypedArray.getColor(TypedArray.java:439) at android.graphics.drawable.VectorDrawable$VFullPath.updateStateFromTypedArray(VectorDrawable.java:1605) at android.graphics.drawable.VectorDrawable$VFullPath.inflate(VectorDrawable.java:1584) at android.graphics.drawable.VectorDrawable.inflateInternal(VectorDrawable.java:666) at android.graphics.drawable.VectorDrawable.inflate(VectorDrawable.java:571) Caused by org.xmlpull.v1.XmlPullParserException: Binary XML file line #9: invalid color state list tag gradient at android.content.res.ColorStateList.createFromXmlInner(ColorStateList.java:217) at android.content.res.ColorStateList.createFromXml(ColorStateList.java:201) at android.content.res.Resources.loadColorStateListForCookie(Resources.java:2956) at android.content.res.Resources.loadColorStateList(Resources.java:2909) at android.content.res.TypedArray.getColor(TypedArray.java:439) This is my vector image <vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:aapt="http://schemas.android.com/aapt" android:width="14dp" android:height="14dp" android:viewportWidth="14" android:viewportHeight="14"> <path android:pathData="M7,0L7,0A7,7 0,0 1,14 7L14,7A7,7 0,0 1,7 14L7,14A7,7 0,0 1,0 7L0,7A7,7 0,0 1,7 0z"> <aapt:attr name="android:fillColor"> <gradient android:endX="7" android:endY="14" android:startX="7" android:startY="0" android:type="linear"> <item android:color="#FF63D8FF" android:offset="0" /> <item android:color="#FF6397FF" android:offset="1" /> </gradient> </aapt:attr> </path> </vector> Can't figure out why the crash is happening?
Thanx to Sandi's comment Replacing android:src with app:srcCompat works
View with svg background crashes on android 6.0 and lower
I have the following situation: I have a constraint layout with background: <androidx.constraintlayout.widget.ConstraintLayout android:id="#+id/cl_wave_header" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#drawable/ic_wave_header_svg_drawable" android:paddingBottom="41dp" app:layout_constraintTop_toTopOf="parent"> Here's the ic_wave_header_svg_drawable: <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="#drawable/ic_wave_header" /> </layer-list> Here's the ic_wave_header: <vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:aapt="http://schemas.android.com/aapt" xmlns:tools="http://schemas.android.com/tools" android:width="328dp" android:height="199dp" android:viewportWidth="328" android:viewportHeight="199" tools:ignore="VectorRaster"> <path android:fillType="evenOdd" android:pathData="M328,198.147C328,198.147 287.806,164.737 164,168.868C40.194,172.999 0,140 0,140V198.147V0H328L328,198.147Z"> <aapt:attr name="android:fillColor"> <gradient android:endX="351.346" android:endY="198.147" android:startX="351.346" android:startY="-28.2069" android:type="linear"> <item android:color="#FF9DDE10" android:offset="0" /> <item android:color="#FF82BD00" android:offset="1" /> </gradient> </aapt:attr> </path> </vector> When I run the app, it crashes on android 6.0 and lower. In the other versions, it works correctly. What's the problem and how can I solve it? UPD Error log: Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_wave_header.xml from drawable resource ID #0x7f080180 at android.content.res.Resources.loadDrawableForCookie(Resources.java:2640) at android.content.res.Resources.loadDrawable(Resources.java:2540) at android.content.res.TypedArray.getDrawable(TypedArray.java:870) at android.graphics.drawable.LayerDrawable.updateLayerFromTypedArray(LayerDrawable.java:296) at android.graphics.drawable.LayerDrawable.inflateLayers(LayerDrawable.java:239) at android.graphics.drawable.LayerDrawable.inflate(LayerDrawable.java:164) at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1215) at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1124) at android.content.res It seems that it is something incorrect with drawable, but if it is right, why it doesn't crash on other devices
In your application class -> enable setCompatVectorFromResourcesEnabled public class App extends Application { #Override public void onCreate() { super.onCreate(); AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);//add this }
This crash is caused by using android:offset="0" in svg file of your drawable. To fix this you can either avoid using android:offset="0" in svg file (by using plain color instead of gradient) or you can use .png format of your drawable image for quick fix.
Android Studio - Fraction values must be in the range 0 to 1: 3.0
<vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:aapt="http://schemas.android.com/aapt" xmlns:tools="http://schemas.android.com/tools" android:width="1080dp" android:height="592dp" android:viewportWidth="1080" android:viewportHeight="592" tools:ignore="VectorRaster"> <path android:pathData="M0,440.31L0,0L1080,0L1080,440.31C952.58,532.86 758.02,592 540,592S127.42,532.86 0,440.31Z"> <aapt:attr name="android:fillColor"> <gradient android:startY="14.208" android:startX="-280.8" android:endY="380.656" android:endX="921.24" android:type="linear"> <item android:offset="0" android:color="#602EC4"/> <item android:offset="1" android:color="#9C7CDD"/> <item android:offset="3" android:color="#8355D1"/> </gradient> </aapt:attr> </path> I am using this code to create a drawable for my app. but I keep getting this error: Fraction values must be in the range 0 to 1: 3.0. My Android Studio Version is 3.6.2
Why do we use drawable v24 in android?
We have a drawable file already in drawable v21 also for ripple effect. So why we use drawable v24 when we are getting vector file already. Below is the xml File ic_launcher_foreground.xml. <vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:aapt="http://schemas.android.com/aapt" android:width="108dp" android:height="108dp" android:viewportHeight="108" android:viewportWidth="108"> <path android:fillType="evenOdd" android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z" android:strokeColor="#00000000" android:strokeWidth="1"> <aapt:attr name="android:fillColor"> <gradient android:endX="78.5885" android:endY="90.9159" android:startX="48.7653" android:startY="61.0927" android:type="linear"> <item android:color="#44000000" android:offset="0.0"/> <item android:color="#00000000" android:offset="1.0"/> </gradient> </aapt:attr> </path> <path android:fillColor="#FFFFFF" android:fillType="nonZero" android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z" android:strokeColor="#00000000" android:strokeWidth="1"/> </vector>
The different drawable folders are for providing different screen densities for device compatibility and for different Android versions. See this answer for more details
Exception from LayerDrawable
I've an android app that using android support library version 23.2.1 and everything is working fine. However, I've updated the android support library version to 25.2.0 yesterday and realize some of the user are getting this exception (through Fabric crashlytics) but I couldn't reproduce it. Here is the crash log: Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.drawable.Drawable android.graphics.drawable.Drawable$ConstantState.newDrawable(android.content.res.Resources)' on a null object reference at android.graphics.drawable.LayerDrawable$ChildDrawable.<init>(LayerDrawable.java:959) at android.graphics.drawable.LayerDrawable$LayerState.<init>(LayerDrawable.java:1007) at android.graphics.drawable.LayerDrawable.createConstantState(LayerDrawable.java:133) at android.graphics.drawable.LayerDrawable.<init>(LayerDrawable.java:126) at android.graphics.drawable.LayerDrawable$LayerState.newDrawable(LayerDrawable.java:1048) at android.content.res.Resources.getCachedDrawableLocked(Resources.java:2777) at android.content.res.Resources.getCachedDrawable(Resources.java:2745) at android.content.res.Resources.loadDrawable(Resources.java:2586) at android.content.res.Resources.getDrawable(Resources.java:900) at android.content.Context.getDrawable(Context.java:408) at android.support.v4.content.ContextCompatApi21.getDrawable(ContextCompatApi21.java:30) at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:372) at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:202) at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:190) at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100) at android.support.v7.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:425) at android.support.v7.view.menu.ActionMenuItemView.initialize(ActionMenuItemView.java:129) at android.support.v7.widget.ActionMenuPresenter.bindItemView(ActionMenuPresenter.java:211) at android.support.v7.view.menu.BaseMenuPresenter.getItemView(BaseMenuPresenter.java:186) at android.support.v7.widget.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:197) at android.support.v7.widget.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:479) at android.support.v7.view.menu.MenuBuilder.flagActionItems(MenuBuilder.java:1160) at android.support.v7.view.menu.BaseMenuPresenter.updateMenuView(BaseMenuPresenter.java:95) at android.support.v7.widget.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:234) at android.support.v7.view.menu.MenuBuilder.dispatchPresenterUpdate(MenuBuilder.java:292) at android.support.v7.view.menu.MenuBuilder.onItemsChanged(MenuBuilder.java:1047) at android.support.v7.view.menu.MenuBuilder.startDispatchingItemsChanged(MenuBuilder.java:1074) at android.support.v7.app.ToolbarActionBar.populateOptionsMenu(ToolbarActionBar.java:460) at android.support.v7.app.ToolbarActionBar$1.run(ToolbarActionBar.java:61) at android.os.Handler.handleCallback(Handler.java:815) at android.os.Handler.dispatchMessage(Handler.java:104) at android.os.Looper.loop(Looper.java:194) at android.app.ActivityThread.main(ActivityThread.java:5637) at java.lang.reflect.Method.invoke(Method.java) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754) It seems to do with menu view. The layout for menu option is: <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:context=".tablet.ui.navimenu.ContainerActivity"> <item android:id="#+id/memo_fragment" android:icon="#drawable/ic_class_white_24dp" android:orderInCategory="100" android:title="#string/memo_fragment" app:showAsAction="always" /> <item android:id="#+id/notification_fragment" android:icon="#drawable/layerlist_menu_notification" android:orderInCategory="200" android:title="#string/notification_fragment" app:showAsAction="always" /> </menu> layerlist_menu_notification layout is an icon with a badge: <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="#+id/ic_notification" android:drawable="#drawable/ic_notifications_white_24dp" android:gravity="center" /> <!-- set a place holder Drawable so android:drawable isn't null --> <item android:id="#+id/ic_badge" android:drawable="#drawable/ic_notifications_white_24dp" /> </layer-list> Any idea where goes wrong?
Try Change the following in build.gradle compileSdkVersion 25 buildToolsVersion "25.0.2" compile 'com.android.support:appcompat-v7:25.1.0' compile 'com.android.support:design:25.1.0' compile 'com.android.support:support-v4:25.1.0'