Comments (39)
Hey, I was just randomly googling about the error "You need to use a Theme.AppCompat theme (or descendant) with the design library", and come to this page.
And especially I see some of you cannot reproduce this problem, I wonder if this is the same as what happened to me.
In fact, I found that "theme" is an "attritube" of context; and LayoutInflator needs to reference a context to inflate Layouts. If you are trying to inflate a layout using a context that does not have the correct theme (e.g. you used getApplicationContext() to obtain a Layout Inflator) then this Layout Inflator may not have the correct context which you have already defined your AppCompact theme.
For example I used
setTheme(R.style.AppThemeWithBackground);
in a BaseActivity which extends AppCompactActivity, and AppThemeWithBackground also inherits an AppCompact theme.
Later if I call this line this BaseActivity
LayoutInflater inflater = (LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
I will get the error.
But if I change it to
LayoutInflater inflater = LayoutInflater.from(this);
Then the error will go away.
Therefore I suspect this is the real cause, so may be restoring the default behavior of design library is better.
from multiline-collapsingtoolbar.
Hi! Thank you for the feedback, we appreciate it.
Could you first confirm that this is a bug that is specific to our library and not a problem with the default CollapsingToolbarLayout
from the Android support library? On first sight, I don't believe this is a problem with our library but the Android support library.
from multiline-collapsingtoolbar.
Yeah, because I am using the default CollapsingToolbarLayout
somewhere else in my appllication... No issue detected
from multiline-collapsingtoolbar.
Are you also using the current version of the Support Library?
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.android.support:design:24.0.0'
Did you try to replace the net.opacapp.multilinecollapsingtoolbar.CollapsingToolbarLayout
with a android.support.design.widget.CollapsingToolbarLayout
to see if the problem persists?
from multiline-collapsingtoolbar.
Yes, all my support library are updated and when I replace "net.opacapp.multilinecollapsingtoolbar.CollapsingToolbarLayout" by "android.support.design.widget.CollapsingToolbarLayout", I have no Issue
from multiline-collapsingtoolbar.
I can't reproduce the bug, even using older Android versions and adjusting the styles from the demo app to the ones you provided.
Does running the demo app work on the same device? If so, could you give us some more code (e.g. the part of your layout XML file where you use net.opacapp.multilinecollapsingtoolbar.CollapsingToolbarLayout
etc.)?
from multiline-collapsingtoolbar.
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/content_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.v4.widget.NestedScrollView
android:id="@+id/nested_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:alpha="0"
android:paddingBottom="80dp"/>
</android.support.v4.widget.NestedScrollView>
<io.codetail.widget.RevealFrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/view_color"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"/>
</io.codetail.widget.RevealFrameLayout>
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:background="@android:color/transparent">
<net.opacapp.multilinecollapsingtoolbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:expandedTitleMarginEnd="@dimen/detail_padding"
app:expandedTitleMarginStart="@dimen/detail_padding"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:alpha="0">
<View
android:id="@+id/empty_color_view"
android:layout_width="match_parent"
android:layout_height="@dimen/header_schedule_height"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"/>
</net.opacapp.multilinecollapsingtoolbar.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<com.swapcard.apps.android.views.likebutton.FloatingLikeButton
android:id="@+id/floating_planning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:layout_margin="@dimen/floating_button_padding"
android:alpha="0"/>
<ProgressBar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/progress_bar_schedule"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone"/>
</android.support.design.widget.CoordinatorLayout>
from multiline-collapsingtoolbar.
Hmm, I still cannot reproduce it.
Is there a way you could set a breakpoint on net.opacapp.multilinecollapsingtoolbar.ThemeUtils:30
and evaluate the expression context.getResources().getResourceEntryName(context.getThemeResId())
there? It seems the theme it obtains there is not an AppCompat theme.
from multiline-collapsingtoolbar.
I have the same issue. A layout with the default android.support.design.widget.CollapsingToolbarLayout
works. When I just replace this by net.opacapp.multilinecollapsingtoolbar.CollapsingToolbarLayout
and add the app:maxLines
attribute I get this error.
from multiline-collapsingtoolbar.
@svenjacobs Just to clarify: Does it work with our layout without the app:maxLines
attribute?
from multiline-collapsingtoolbar.
@raphaelm No, it doesn't work without app:maxLines
. Just replacing CollapsingToolbarLayout
in the layout suffices to provoke this error.
from multiline-collapsingtoolbar.
@svenjacobs Could you try if it works with an older version of the library?
compile 'net.opacapp:multiline-collapsingtoolbar:1.1.0'
If that is the case, I think I know where the problem is.
from multiline-collapsingtoolbar.
@johan12345 Same error with version 1.1.0
from multiline-collapsingtoolbar.
@svenjacobs Hm, strange.
As I wrote before:
Is there a way you could set a breakpoint on net.opacapp.multilinecollapsingtoolbar.ThemeUtils:30 and evaluate the expression context.getResources().getResourceEntryName(context.getThemeResId()) there? It seems the theme it obtains there is not an AppCompat theme.
from multiline-collapsingtoolbar.
@johan12345 See attached screenshot
from multiline-collapsingtoolbar.
Update: Please forget my last comment. My evaluation was wrong. Here's the correct screenshot.
@johan12345 And here's the same evaluation with the original CollapsingToolbarLayout
from Android Design Support 24.0.0.
The value of TypedArray a
is different but I'm not sure why...
from multiline-collapsingtoolbar.
I still can't reproduce the issue and don't see where it comes from looking at the screenshots.
In 97e1bbe, I commented out the call to checkAppCompatTheme
. Maybe it just works without it? It is not absolutely necessary for us to include the check in this library, as it should already be done by the other Design Library components (e.g. AppBarLayout
).
from multiline-collapsingtoolbar.
Without looking at the source code, could it be that your CollapsingToolbarLayout
does not inherit from the correct base theme of the support library?
from multiline-collapsingtoolbar.
Well, a View
can't inherit from a Theme
, the theme is set by the LayoutInflater
depending on the Activity
theme (or additional themes specified in the XML layout). All the code (except for the changes that were marked) is basically copied from the support library.
from multiline-collapsingtoolbar.
I'm aware of that ;) I was talking about the style which is applied to the view.
from multiline-collapsingtoolbar.
Ah, okay. If that's the issue, it should work with version 1.0.1
(and Support Library 23.2.1), which did not need any custom styles (it didn't even have a src/main/res
folder).
from multiline-collapsingtoolbar.
And one more thing I haven't asked yet: Does this issue also appear with our demo app or only when using the library in your own application? And does it only appear on a specific device/Android version?
from multiline-collapsingtoolbar.
@johan12345 Here are a few answers:
- The demo application works on the same device (Nexus 5, Android 6.0.1)
- My application with your library version 1.2.1 crashes on a Nexus 5 and Nexus 5X (both Android 6.0.1)
- My application does not crash with version 1.0.1 of your library and Android Support 23.2.1 (Same devices used for testing)
from multiline-collapsingtoolbar.
@svenjacobs Oh, okay, so it is definitely related to some of the styles/themes you have in your app. Maybe you could share some of those (and the layout attributes of the CollapsingToolbarLayout) so I can try to reproduce it in the demo app? Or try to copy them over to the demo app to find out which of them causes the crash?
from multiline-collapsingtoolbar.
This is a snippet from our styles.xml
. I removed all attributed which are hopefully not related to this issue:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primary_500</item>
<item name="colorPrimaryDark">@color/primary_700</item>
<item name="colorAccent">@color/primary_700</item>
<item name="colorControlHighlight">@color/colorControlHighlight</item>
</style>
<style name="AppTheme.Launch">
<item name="android:windowBackground">@drawable/splash_screen</item>
</style>
The AppTheme.Launch
theme is applied to <application>
in AndroidManifest.xml
. We do not set any Activity
theme in the manifest. We programmatically change the theme to AppTheme
in onCreate()
of an Activity
like described here.
This is the layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="@dimen/recipes_details_backdrop_height"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:visibility="gone"
tools:visibility="visible">
<net.opacapp.multilinecollapsingtoolbar.CollapsingToolbarLayout
android:id="@+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:collapsedTitleTextAppearance="@style/CollapingToolbar.CollapsedTitleTextAppearance"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="16dp"
app:expandedTitleMarginStart="16dp"
app:expandedTitleTextAppearance="@style/CollapingToolbar.ExpandedTitleTextAppearance"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/empty_content_description"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="@id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
</net.opacapp.multilinecollapsingtoolbar.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/contentView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
from multiline-collapsingtoolbar.
@svenjacobs In 988fce8 (on the branch svenjacobs-style-tests
), I copied most of your styles to the demo app, and it is still running fine for me (Nexus 5X/6.0.1 and Moto G2/6.0)... :/
from multiline-collapsingtoolbar.
@johan12345 Are you sure that in version 1.2.1 of your library you properly copied all files from Android Support 24.0.0? Because what's odd is that your library in version 1.0.1 works with my project...
from multiline-collapsingtoolbar.
@svenjacobs That's indeed odd, but when I can't reproduce the issue, its difficult to find out what change after version 1.0.1 caused it.
from multiline-collapsingtoolbar.
I use a custom view in fragment containing this Activity。THIS IS led to the emergence of error.
Sorry, I used Google Translation
from multiline-collapsingtoolbar.
@geekvxyz Is there any way you can give me a minimal example that reproduces the issue, e.g. by modifying the demo app?
from multiline-collapsingtoolbar.
@johan12345 The issue came me up with the version 1.2.2 too. I could fix the bug, commenting the exception IllegalArgumentException inside the method checkAppCompatTheme(Context context)
of the class ThemeUtils
. It tested with a Nexus 5 and com.android.support:design:24.1.1
. What is that validation for?
from multiline-collapsingtoolbar.
@castrojr913 Well, that validation is directly copied from the Support Library, so I don't understand why it doesn't work here.
Additionally, this problem never showed up in crash reports from our app or when testing the demo app. This is why I am still asking for an example project (e.g. based on the demo app) where the problem occurs so that I can reproduce it.
But on the other hand, I guess it would not matter very much if we simply removed that validation, as it will still be performed by all the Support Library components. @raphaelm, what do you think?
from multiline-collapsingtoolbar.
Having the same issue, with the same theme. Was a fix/workaround decided for this issue?
from multiline-collapsingtoolbar.
@cameronlund4 As mentioned above, the fix seems to be removing the validation. But before we include this change in a new release of the library, I would like to be able to reproduce the issue. Are you able to provide a minimal working example that shows the bug?
from multiline-collapsingtoolbar.
@cameronlund4 I created a fork, fixing this issue. Please, declare on build.gradle
:
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
compile 'com.github.castrojr913:multiline-collapsingtoolbar:v1.2.2'
}
from multiline-collapsingtoolbar.
@castrojr913 As I said, we would also incorporate this change into our version on JCenter, but before that, I would like to to reproduce the crash and find out what causes it. And as nobody provided an example project, I was not able to do so. 😕
from multiline-collapsingtoolbar.
It seems that @jfri found a more elegant solution to this problem without telling us 😉. I just merged it and it will be included in the next release.
from multiline-collapsingtoolbar.
@johan12345 oh, good news :)
from multiline-collapsingtoolbar.
Should be in the 1.3.0 release :)
from multiline-collapsingtoolbar.
Related Issues (20)
- Align background with expanded text HOT 3
- Scrim color doesn't persist HOT 2
- Text get duplicated if it's not in English HOT 1
- Revert to single line when changing title text size with TextAppearance HOT 1
- Multiline not working with TextSize<21 SP HOT 4
- How to fix Toolbar Background color?
- Error HOT 2
- How to enlarge image on a backdrops HOT 1
- expandedTitleMarginEnd not working
- New line without the need HOT 5
- Failed to resolve: net.opacapp:multiline-collapsingtoolbar:1.6.0 HOT 6
- Link versions to support library dependency version HOT 3
- Update library to Support Library version 27.1.1 HOT 1
- Add subtitles HOT 1
- crash-CollapsingTextHelper#calculateUsingTextSize HOT 2
- Update library to Support Library version 28.0.0 HOT 3
- Migrating to AndroidX HOT 7
- Custom Font family HOT 1
- Duplicated title HOT 7
- JCenter migration HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from multiline-collapsingtoolbar.