I'm trying to make an Android app through Xamarin. I work on Windows 10 with VS2015.
I have to implement a side bar menu. After some research I found a solution to do it : use a DrawerLayout and others tools. That's why I use Theme.AppCompat in my application.
But when I'm trying to make a style which herits from Theme.Appcompat.light.NoActionBar, I got compile issue. The message is :
Error retrieving parent for item: No resource found that matches the given name '#android:style/Theme.AppCompat.Light.NoActionBar'.
I've added Xamarin.Android.Support.v4 and Xamarin.Android.Support.v7.AppCompat references to my project as bellow :
Project References
Edit: I also tried to add them by xamarin Component and nuget package manager.
But nothing compile.
Here is the code which produce this error:
<resources>
<style name="DailyCoin.HomeTheme" parent="#android:style/Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#219653</item>
<item name="drawerArrowStyle">#style/MyDrawerArrowStyle</item>
</style>
<style name="MyDrawerArrowStyle" parent="#android:style/Widget.AppCompat.DrawerArrowToggle">
<item name="color">#F5F5F5</item>
<item name="spinBars">true</item>
</style>
</resources>
minSdkVersion is 17 and compile using version is 23
Ok, I found the solution.
My problem was that xamarin was corrupted and the component adding module had some troubles when i added components. So i removed all references/components i've added to my projet, reinstalled xamarin.
Just for people impatient like me:
Then i had a new issue : "Unzipping failed. Please download https://dl-ssl.google.com/android/repository/android_m2repository_r28.zip" because when generated the solution, it took a lot of time and i stoped this.
The solution was to delete all zips in "%localappdata%/xamarin/zips" and wait for the generation.
Thank for your help !
Julien
Did you try this?
parent="Theme.AppCompat.Light.NoActionBar"
Check this out (its working for me): Navigation Drawer using material design
Leave out #android:style/ so just:
parent="Theme.AppCompat.Light.NoActionBar"
Related
First of all, I researched alot and this question is not a duplicate of Rendering Issue in Android Studio its answer doesn't fix my problem (i already have the same configuration that is in its answer). Secondly I tried cleaning project, rebuilding project, running gradle sync too. Issue still persist.
After starting a new project, i used to load a template basic activity but the layout xml files are actually not rendering.
Error:
It says Failed to instantiate one or more classes inside that i see
The following classes could not be instantiated:
- android.support.design.widget.CoordinatorLayout (Open Class, Show Exception, Clear Cache)
- android.support.design.widget.AppBarLayout (Open Class, Show Exception, Clear Cache)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE.
If this is an unexpected error you can also try to build the project, then manually refresh the layout.
Exception Details
java.lang.ClassNotFoundException: android.view.View$OnUnhandledKeyEventListener
Copy stack to clipboard
my styles.xml file is:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="coordinatorLayoutStyle">#style/Widget.Support.CoordinatorLayout</item>
<item name="floatingActionButtonStyle">#style/Widget.Design.FloatingActionButton</item>
<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"/>
</resources>
My gradle is using this dependency: and compilation and target sdk version is 28
implementation 'com.android.support:appcompat-v7:28.0.0'
Right now it looks like:
EDIT 1:
So now at this point, i tried many things and found myself that the rendering issue is only in SdkVersion 28. When I use
android {
compileSdkVersion 27
defaultConfig {
targetSdkVersion 27
...
}
...
}
dependencies {
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
...
}
It doesn't appear to be, so I want to investigate what's wrong with sdk version 28? I mean like whenever you make a project you get default config for version 28 and when i try this above snippet i still get warning that v27 is older, why? if v28 not stable enough then why is it default? I don't understand I want some useful answer for why this is!
Thanks everyone who used time to read my question.
Before proceeding with the answer, make sure you have the latest Android Studio. It handles API v28 in a much better way. This update on its own might solve your problem, but if it doesn't, read below:
AndroidX
Try migrating to AndroidX. In the latest Android Studio 3.2 there is a feature called 'Refactor to AndroidX' under the 'Refactor' menu, which makes the whole process easier.
AndroidX is basically google renaming all of the packages to make the naming clearer. More information on that can be found here and here.
I know this is not a direct answer to your question, but I am confident it will solve it. There are many bugs and other irritating errors that Android Studio produces, that I don't see any other IDE makes - I am referring to those that are unclear about what went wrong.
I believe by making AndroidX google addresses this issue in some way. It does definitely make some things clearer and easier, and I recommend migrating to it, in order to solve your problem, and for good practice.
I'm trying to use the CoordinatorLayout in my Xamarin.Android app. I've been using a custom theme with Theme.Material.Light as its parent, which worked fine before I added the CoordinatorLayout. When I add it, I get an error telling me I have to use a Theme.AppCompat theme, but as soon as I do the app fails to build and gives me the following error:
/{project directory}/Resources/values/Styles.xml(0,0):
Error APT0000: Error retrieving parent for item:
No resource found that matches the given name
'#android:style/Theme.AppCompat'. (APT0000) (TnpApp.Android)
This answer suggests installing the major version of the support library that matches the Android SDK I'm using. I've tried this (I think I did everything correctly), but it doesn't help.
Does anyone have any ideas?
I'm using Xamarin Studio on Mac.
UPDATE 1
I tried the following code in MainActivity.cs in a clean Xamarin.Android project, and build fails with the same error.
namespace ThemeTest
{
[Activity(Label = "ThemeTest", MainLauncher = true, Icon = "#mipmap/icon", Theme = "#android:style/Theme.AppCompat.Light")]
public class MainActivity : Activity
{
// ...
}
}
UPDATE 2
I removed all the folders from /user/.local/share/Xamarin except for Mono for Android and zips as suggested in this answer. I closed Xamarin Studio and reopened it. I tried to deploy the app, and Xamarin reinstalled all the packages but the build failed with the original error.
I was able to fix this problem by simply removing #android:style/ from the style element's parent tag in my Styles.xml file. So what looked like this...
<style name="MyCustomTheme" parent="#android:style/Theme.AppCompat">
Now looks like this...
<style name="MyCustomTheme" parent="Theme.AppCompat">
I'm shocked the solution is this simple, but it works. :) I got the idea from this code.
I'm developing in Visual Studio 2015/Xamarin and saw this same problem. While I still don't understand the cause or the fix for this problem, this thread did point me in the right direction which seems to have more to do with resaving styles.xml (for my development environment) than anything else.
My styles.xml did not have #android:style/ and I still had the error mentioned above. As described in another proposed solution, I added
<style name="MyCustomTheme.Base" parent="Theme.AppCompat" />
before <style name="MyCustomTheme" parent="Theme.AppCompat">, saved styles.xml and rebuilt my project without errors. I then removed
<style name="MyCustomTheme.Base" parent="Theme.AppCompat" />,
resaved styles.xml and rebuilt with no errors. Visually, my styles.xml is unchanged, but the error is gone.
If you recently installed a google play service related package (firebase for example , but there are many others) , it is possible that this installation messed up with your CSproj and your package.json files (look at your version control history to see if these files were changed), and modified your target api version : Going from target Api 25 to Target 26 for exemple etc.
If this is the case , you should adresse this problem one of two ways :
make sure you download the sdk version that you are now targeting , to do this , go to TOOLS > SDK manager.
or revert back to your old target , by discarding the change the package made to you csproj and package.json files and clean and rebuild.
I am facing some bug with custom material theme with AppCompat
I already set the the target to android 5.0
I already download the android support repository through the android sdk manager
and I add the AppCompat packege already
I will provide you some screenschot so you might help me figure out what's going wrong with it. Thank you in advance
Error Log
here is my style xml for the color
<?xml version="1.0" encoding="UTF-8" ?>
</style>
<style name="Theme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#9E9E9E</item>
<item name="colorPrimaryDark">#616161</item>
<item name="colorAccent">#FF5252</item>
<item name="colorControlHighLight">#F5F5F5</item>
</style>
You are most likely running into an issue with the Support library Caches. We wrote a troubleshooting document on this topic that should help you resolve this:
https://developer.xamarin.com/guides/android/troubleshooting/resolving-library-installation-errors/
(Gist - https://gist.github.com/JonDouglas/f6291eacd4da5f6aa4cd)
Goto C:\Users\Geeksan\AppData\Local\Xamarin folder & Delete all folders corresponding to Android packages. Also delete zip files from the zips folder.
Then from your solution, add the required packages from nuget again & build the solution. The build process will take some time to download the zip files & unpack them. So wait for build to complete. Do not cancel the build process.
I recently updated Android Studio to version 1.2 and my AppCompat library to v22.0.0, SDK-Build-Tools version to 22.0.1. My target and compile sdk-version is 22 and my 'min-sdk-version' is 16.
The problem I am having is that in the xml-layout preview, I am getting an error namely: "Rendering Problems, the following classes cannot be found: android.support.v7.widget.Toolbar". I did some surfing on the internet and tried the already provided solutions. They are as follows:
Changing my (xml) preview to show android version target 21 or Android 5.0.1, 19, and 17
Changing my styles theme to Holo.NoActionBar and other themes as well.
Changing my minSdkVersion to 21 (above 20 basically)
Restarted Android Studio... Twice
Built the project about 5 times.
However, the problem still remains and I'm out of ideas. Could really use some help here. Thanks...
Also: The classes import just fine in my java file. It's just the preview.
EDIT: The preview works fine when I use android.widget.Toolbar. And my DrawerLayout doesn't work. I'm guessing there's something wrong with rendering the widgets from the support libraries?
I had a similar problem and you may want to try to change the app theme in the style.xml to an appcompat app theme for example with mine I changed it to something like this.
<style name="AppTheme" parent="#style/Theme.AppCompat.NoActionBar">
<item name="windowActionBar">false</item>
<!-- Customize your theme here. -->
</style>
and then go to the Android Manifests file
<application
android:theme="#style/whatever_you_named_your_app_theme">
In the Android Manifests file you write whatever you wrote in the styles.xml under <style name=""
There is no need to lower your apps targetSDK.
Give me feedback if it worked for you
I wiped out my entire project and started all over again. That seemed to solve the problem. I'm guessing changing my configurations in between is what caused the mess. Thank goodness the project was just for recreation.
Following a tutorial, I have a styles.xml file with the following code:
<style name="ActionBar.Solid.Sunshine"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
Android Studio gives me the error that Widget.Appcompat.Light and Widget.Appcompat cannot be resolved, although it still works at build time. I am a beginner and am quite at lost as to what caused this error. Any pointers?
On another related note, where do I find the list of default resources I can use, such as the Widget given to me above?
Thanks!