Trouble with content_main.xml - android

I am fairly new to android and am trying to create an app in android studio The problem is the content_main.xml isn't working correctly. I used to be able to drag and drop button and such exactly where I wanted, but now I can't. My screen looks like :
.
The errors I am getting are:
Failed to find style 'coordinatorLayoutStyle' in current theme and two long errors that are shortened to missing styles and failed to instantiate one or more classes.
<resources>
<!-- 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>
</style>
<!--<style name="AppTheme.NoActionBar">-->
<!--<item name="windowActionBar">true</item>-->
<!--<item name="windowNoTitle">true</item>-->
<!--</style>-->
<style name="AppTheme.NoActionBar">
<item name="coordinatorLayoutStyle">#style/Widget.Design.CoordinatorLayout</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
Any help would be great all the other answers to similar questions seem to deal with previous versions and none of it has done the trick. Any help is very much appreciated.

Related

How to disable or program dark/night mode in Android Studio?

I want to know if it is possible to disable night/dark mode into android studio´s apps because, in my case, it breaks my app´s aesthetic.
I´ve tried using this code line into all my activities but it didn´t work:
setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
If there aren´t any way to disable night/dark mode, can you tell me what do i have to do in order to make my app respond properly to color changes due to night/dark mode? (This includes background colors, drawable´s shapes colors and every color that gets modified by this mode)
(I accept documentation or any kind of information that can helps me solving this BIG problem)
My styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light">
<item name="android:padding">7dp</item>
</style>
</resources>
Finally solved the problem disabling dark/night mode. We have to add the following code into our AppThemes:
<item name="android:forceDarkAllowed">false</item>

ScrimBackground from Theme.MaterialComponents is not Working

I'm trying to change the scrimBackground that show up when you opened a dialog. And I know that in the new MaterialComponents-Theme is an attribute for this case (scrimBackground). But it is currently not working for me.
On the material.io website that background is also descriped as the scrimBackground and it looks like that it is customizable from the Theme. Has anyone an idea what I'm doing wrong?
https://material.io/design/components/dialogs.html#theming
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="scrimBackground">#android:color/holo_blue_light</item>
<item name="dialogTheme">#drawable/window_scrim</item>
<item name="android:dialogTheme">#style/DialogTheme</item>
<item name="alertDialogTheme">#style/AlertDialogTheme</item>
<item name="android:alertDialogTheme">#style/AlertDialogTheme</item>
</style>
<style name="DialogTheme" parent="Theme.MaterialComponents.Dialog">
<item name="scrimBackground">#drawable/window_scrim</item>
</style>
<style name="AlertDialogTheme" parent="Theme.MaterialComponents.Dialog.Alert">
<item name="scrimBackground">#drawable/window_scrim</item>
</style>
The Material code does not appear to use this attribute even though it is defined. This issue tracks this problem. In the meantime, you may be able to change this without a Material Theme using the advise in Changing default Android fade/scrim color when calling a Dialog.

Failed to find style ... in current theme

I've faced a questionable error during my work with android studio.
Everytime I start studio and create a new project there is another render error
Failed to load AppCompat ActionBar with unknown error.
I do not clearly understand what does it mean, but it is easy to deal with it via replacing
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to:
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
but evertime I add new element to the layout, there is error
Failed to find style ... in current theme
I have found a solution, that helped almost everybody except me. But changing theme now doesn't solve the problem.
If anybody know how to deal with it please help.
You can copy the style name floatingactionbuttonstyle and included it in your apptheme.
Add this line
<item name="floatingActionButtonStyle">#style/Widget.Design.FloatingActionButton</item>
And finally theme look like this
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="floatingActionButtonStyle">#style/Widget.Design.FloatingActionButton</item>
</style>
Just add the style name when error occured in layout editor & add the responding styles.
Here some other few elements am added in styles for others.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="chipStyle">#style/Base.Widget.MaterialComponents.Chip</item>
<item name="chipGroupStyle">#style/Widget.MaterialComponents.ChipGroup</item>
<item name="bottomNavigationStyle">#style/Widget.Design.BottomNavigationView</item>
<item name="coordinatorLayoutStyle">#style/Widget.Support.CoordinatorLayout</item>
<item name="bottomAppBarStyle">#style/Widget.MaterialComponents.BottomAppBar</item>
<item name="floatingActionButtonStyle">#style/Widget.Design.FloatingActionButton</item>
</style>
You can add default style with style name. Then you resolve this error.
In your app gradle under dependencies use this:
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
if you heven't already.

Style showing error in android

The following style shows error in eclipse
<style name="AppTheme" parent="android:style/Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="colorControlNormal">#color/primary</item>
<item name="colorControlActivated">#color/primary</item>
<item name="colorControlHighlight">#color/primary</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#color/white</item>
</style>
it shows a error like this
error: Error retrieving parent for item: No resource found that matches the given name 'android:style/Theme.AppCompat.Light.NoActionBar'.
while i searched, i get to know that it is the problem of the dependency. I tried a lot to solve it. But i still get the same error .
If i change the theme there is no error, but i need this particular style.
I tried the following theme
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
// Your style here
this is woking . but i need the above theme .
If your activity extends AppCompactActivity, your parent theme should be
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light.NoActionBar" />
where as, if using ActionBarActivity, theme should be
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar" />
Make sure you have set up the dependencies in your project. This feature required appcompactv7.

Android actionbar background around title

Android Studio 1.1.0. SDK 22 Installed&Compiled, SDK 17 Target (I suppose it's not relevant, because issue occurs also on preview in IDE).
I started playing with Holo theme action bar styling and ran into an issue, involving background color. This is my styles.xml:
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:background">#ff0d3200</item>
<item name="android:actionBarStyle">#style/BarTheme</item>
</style>
<style name="BarTheme" parent="android:Widget.Holo.ActionBar">
<item name="android:background">#443322</item>
</style>
</resources>
And this is output. I want app title's background color to be the same as action bar's. As I've said, it's the same on the preview, so I don't think it's because my phone(SDK17) or emulator. Overflow button behaves the same way, there just isn't any in this case.
I tried setting android:titleTextStyle in BarTheme to this style:
<style name="TitleTheme" parent="android:TextAppearance.Holo">
<item name="android:background">#443322</item>
</style>
But it didn't change a thing. What do I do to overcome this?
try ,
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">value</item>
<item name="android:titleTextStyle">#style/TitleColor</item>
</style>
<style name="TitleColor" parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">value</item>
</style>
Due to David's input I solved my problem myself. I had to set windowBackground, instead of background in AppTheme. I'm not sure what is the exact difference, but it works properly. Remember not to change attribute in your BarTheme, because it won't work with windowBackground. Therefore correct styles.xml file is:
<resources>
<color name="bcColor">#ff0d3200</color>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:windowBackground">#color/bcColor</item>
<item name="android:actionBarStyle">#style/BarTheme</item>
</style>
<style name="BarTheme" parent="android:Widget.Holo.ActionBar">
<item name="android:background">#443322</item>
</style>
</resources>
Note that color has to be defined as resource in this case and cannot be hardcoded. The clean way to do this is create colors.xml in values folder and define all colors there.

Categories

Resources