Here is a case that instant run in AS is not working:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
toolbar.setElevation(visible ? getResources().getDimension(R.dimen.elevation_toolbar) : 0);
} else {
View toolbarShadow = findViewById(R.id.toolbar_shadow);
toolbarShadow.setVisibility(visible ? View.VISIBLE : View.GONE);
}
The view in layout
has the R.id.toolbar_shadow
. All good.
However if you have a view in layout-21
which does not contain the R.id.toolbar_shadow
then when you compile the app to an e.g. Api 23
device gradle will fail with :
Error:(1046, 42) error: cannot find symbol variable toolbar_shadow
Any ideas to solve this?
Update: as requested the layouts:
res/layout/actionbar.xml
:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
... >
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
... />
<View
android:id="@+id/toolbar_shadow"
... />
</LinearLayout>
res/layout-21/actionbar.xml
:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
... />