Another "Failed to load AppCompat ActionBar with unknown" error issue - android

I cannot see my layouts in the layout editor. The error message is whats in the title.
Not sure how many of these topics need to exist and why Android is such a black hole when it comes to issues, but I'm still having problem with this:
This project uses:
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v13:28.0.0'
What I have in my styles file:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="colorControlNormal">#color/menu_yellow</item>
<item name="colorControlActivated">#color/menu_yellow</item>
<item name="colorControlHighlight">#color/menu_yellow</item>
</style>
So the idea was to replace it to Base.Theme.AppComat.Light based on other answers:
<!-- Base application theme. -->
<style name="AppTheme" parent="Base.Theme.AppCompat.Light">
<!-- Customize your theme here. -->
...
</style>
Now this just gives me a "resource not found (Base.Theme.AppCompat.Light)"
Either way I have tried a lot of suggested solutions back from 28 alpha but none of them work now with released 28.

try this way
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="colorControlNormal">#color/menu_yellow</item>
<item name="colorControlActivated">#color/menu_yellow</item>
<item name="colorControlHighlight">#color/menu_yellow</item>
</style>

maybe this help you
in the styles.xml replace
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
with
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

Related

what's the difference between windowActionBar and android:windowActionBar

when I set thestyle in this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
the actionbar will go away.
however,when I set it in this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowActionBar">false</item>
<item name=“android:windowNoTitle">true</item>
</style>
the actionbar is still here.
what's the difference ?
windowActionBar is an attribute provided in AppCompat library, where as android:windowActionBar is provided in Material theme.
The action bar is going away when you set below code, just because you are using AppCompat library and referring the attribute provided in this library itself:
<item name="windowActionBar">false</item>
On another points, it's same as colorPrimary and android:colorPrimary attribute and all other similar attributes.
For example:
We were using Material theme and referring android:colorPrimary attribute as below:
<style name="AppTheme" parent="android:Theme.Material.Light">
<item name="android:colorPrimary">#color/primary</item>
<item name="android:colorPrimaryDark">#color/primary_dark</item>
....
....
</style>
but we are now using AppCompat library with only colorPrimary attribute, for providing compatibility to lower versions.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
...
...
</style>
android:windowActionBar denotes property for lollipop and above only. Where as windowActionBar denotes for all versions and is retrieved from support library.

change homeAsUpIndicator icon in android kitkat

I tried to change the default icon of HomeAsUpEnabled by editing my styles.xml file. But my icon did't changed. I am working on min sdk version:23. Below is my styles.xml file.
My styles.xml file
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:homeAsUpIndicator">#drawable/back</item>
<item name="homeAsUpIndicator">#drawable/back</item>
</style>
Use the Toolbar and call toolbar.setNavigationIcon(). See more on toolbar here http://developer.android.com/reference/android/widget/Toolbar.html

Android style inheritance

I have two themes, one has ActionBar and one without. It seems redundant to do duplicate the styles, is there any way to simplify it?
Thanks
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/primary_color</item>
<item name="android:windowBackground">#color/bg_color</item>
<item name="colorAccent">#color/accent_color</item>
<item name="colorPrimaryDark">#color/darker_color</item>
<!-- Button style -->
<item name="android:buttonStyle">#style/ButtonStyle</item>
<item name="buttonStyle">#style/ButtonStyle</item>
</style>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/primary_color</item>
<item name="android:windowBackground">#color/bg_color</item>
<item name="colorAccent">#color/accent_color</item>
<item name="colorPrimaryDark">#color/darker_color</item>
<!-- Button style -->
<item name="android:buttonStyle">#style/ButtonStyle</item>
<item name="buttonStyle">#style/ButtonStyle</item>
</style>
<style name="ButtonStyle" parent="Widget.AppCompat.Button">
<item name="android:background">#color/primary_color</item>
</style>
Unfortunately, due to the way that Style/Theme inheritance works, there is no way around this. You could read more about that here:
Android Styles heritage
One option, however, would be to copy the contents of the NoActionBar theme. It turns out that it only contains 2 lines:
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
So your code would look like this
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/primary_color</item>
<item name="android:windowBackground">#color/bg_color</item>
<item name="colorAccent">#color/accent_color</item>
<item name="colorPrimaryDark">#color/darker_color</item>
<!-- Button style -->
<item name="android:buttonStyle">#style/ButtonStyle</item>
<item name="buttonStyle">#style/ButtonStyle</item>
</style>
<!-- NoActionBar theme -->
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Now you are inheriting the AppTheme attributes as well as getting the NoActionBar behavior. Obviously this is not foolproof if the attributes of NoActionBar change in the future, but it might be a good option for someone with many attributes in their base AppTheme.

No resource found that matches the given name: attr 'colorBackground'

I am trying to edit the ThemeOverlay here which contains the dewfaults regarding the popups and dialogs and things like that but the problem is that it is not accepting the colorBackground attribute.
I know that some will say that I should use android:colorBackground but if I am inheriting from AppCompat then it should not be a problem.
Please help.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base">
<!-- Customize your theme here. -->
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#color/Primary</item>
<item name="colorPrimaryDark">#color/PrimaryDark</item>
<item name="colorAccent">#color/Accent</item>
</style>
<style name="PopupTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="colorBackground">#color/TextColor</item>
</style>
</resources>
Also, even after applying android:colorBackground it doesn't work. The error is gone but what I want to get done doesn't happen.
Try changing to :
<style name="PopupTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="android:background">#color/TextColor</item>
</style>
i think you are trying to change the background, why not using an image:
<item name="android:background">#drawable/your_drawable</item>
changing
<style name="PopupTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="colorBackground">#color/TextColor</item>
</style>
to
<style name="PopupTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="android:windowBackground">#color/TextColor</item>
</style>

Material Design: EditText's highlight color becomes half transparent

In Android 5.0 device, you can see the highlight color overlaps the normal color.
In Android 4.4.4(the normal case),
My EditText:
<EditText android:layout_width="320dp"
android:layout_height="wrap_content"
android:id="#+id/account"
android:padding="16dp"
android:singleLine="true"
android:imeOptions="actionNext"/>
Style:
<style name="AppTheme" parent="AppTheme.Base"/>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorControlNormal">#color/colorPrimary</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowActionModeOverlay">true</item>
</style>
v21 Style
<style name="AppTheme" parent="AppTheme.Base">
</style>
I don't know why this happened.
The code works great at another app.
But I could not find any difference between two apps.
Does anyone know about this ?
Thanks!
[UPDATE]
Sorry, also happen to the other projects with the same code.
OK,
I report the issue and got reply from Google.
The EditText drawables were updated in 5.1 (which is what 4.4 and below are using).
Since the visual change is small it's not worth updating these for 5.0.x.
Thanks for the report though.
add this for your styles.xml(v19) and styles(v22) :
#color/colorHighlight
You can do like this :
in the styles.xml :
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorPrimaryDark</item>
<item name="android:windowBackground">#android:color/white</item>
</style>
and for styles.xml(v19) :
<style name="AppTheme" parent="AppTheme.Base">
<item name="android:windowTranslucentStatus">true</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="colorControlHighlight">#color/colorHighlight</item>
and for styles.xml(v22) :
<style name="AppTheme" parent="AppTheme.Base">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="android:colorAccent">#color/colorAccent</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:colorControlHighlight">#color/colorHighlight</item>
<item name="android:windowContentTransitions">true</item>
<item name="android:windowTransitionBackgroundFadeDuration">5000</item>
</style>

Categories

Resources