I want to create a splash screen to my Android program. I am using C# and Xamarin in Visual studio to write my app.
I have followed a Xamarin Tutorial on how to create splash screen, when building the app, it gave me this error:
Error retrieving parent for item: No resource found that matches the
given name (Theme.AppCompat.Light)
in my Style.xml.
Here is my Style.xml file:
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="MyTheme.Base" parent="Theme.AppCompat.Light">
</style>
<style name="MyTheme" parent="MyTheme.Base">
</style>
<style name="MyTheme.Splash" parent ="Theme.AppCompat.Light">
<item name="android:windowBackground">#drawable/splash_screen</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>
I have searched all the internet for a solution to my problem but didn't worked. Please don't consider it as duplicate cause I have seen all the answers and they didn't fixed my problem.
Related
I'm new in Xamarin. I want to learn about <Style> tag. I have problem When I start adding tag on App.xaml file,warning message appear.I don't know what mistake that i make. Hope you guys can help me solve this problem.Thank you in advance.
Error Message
App.xaml
<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TravelRecordApp.App">
<Application.Resources>
<!-- Application resource dictionary -->
<ResourceDictionary>
<Color x:Key="blueColor">#1E90FF</Color>
<Color x:Key="whiteColor">#FFFFFF</Color>
<Style>
<Setter Property="BackgroundColor" Value="{StaticResource blueColor}" />
<Setter Property="TextColor" Value="{StaticResource whiteColor}"/>
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
A Style tag must always specify the TargetType. So if, for instance, your style targets labels, you would have to change your code to:
<Style TargetType="Label">
<Setter Property="BackgroundColor" Value="{StaticResource blueColor}" />
<Setter Property="TextColor" Value="{StaticResource whiteColor}"/>
</Style>
By the way, the Xamarin.Forms previewer is a pain in the a**. The error message you're getting probably won't go away even after you fixed it. I had to do a complete clean & rebuild, then open the previewer for a different page, close it and open it again for the page I wanted before it would display anything.
You may be better off not using it.
Another issue could be is that you have some code in the App.xaml.cs in the App() constructor that could be causing the issue as well. For instance I fixed a problem in some code that I inherited that was trying to connect to a database so I fixed it like this:
public App()
{
InitializeComponent();
if (DesignMode.IsDesignModeEnabled)
{
return;
}
// connect to database code here
You can use DesignMode.IsDesignModeEnabled to determine if you are running in the designer or elsewhere. You may also want to check your constructors in your xaml.cs files and see if they are trying to run any code that would cause the designer to throw that exception as well.
If anyone is still having an issue with this, what fixed it for me is going to my NuGet package manager and updating Xamarin Forms to the latest version.
Instantly fixed the issue for me.
Good luck!
I'm struggling with creating a splash screen using (XML-based) vector drawables on old Android versions (API 16) in Xamarin.Android. I've read a lot of similar questions, but I can't get it to work no matter what I try.
I currently have the following, which works fine on recent Android versions (e.g. API 25):
drawable/itlogotext.xml:
<vector xmlns:android="http://schemas.android.com/apk/res/android" [...]>
[...]
</vector>
drawable/splash_screen.xml:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="#3498DB" />
</item>
<item
android:drawable="#drawable/itlogotext"
android:gravity="center" />
</layer-list>
values/styles.xml:
<resources>
[...]
<style name="MyTheme.Splash" parent ="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#drawable/splash_screen</item>
<item name="colorPrimaryDark">#1B6698</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>
SplashActivity.cs:
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Support.V7.App;
using JetBrains.Annotations;
[Activity(Theme = "#style/MyTheme.Splash", MainLauncher = true, NoHistory = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
ScreenOrientation = ScreenOrientation.Portrait)]
public sealed class SplashActivity : AppCompatActivity
{
protected override void OnResume()
{
base.OnResume();
this.StartActivity(new Intent(Application.Context, typeof(MainActivity)));
}
}
I have the latest support libraries (26.1.0.1, including Xamarin.Android.Support.v4 and Xamarin.Android.Support.v7.AppCompat, the latter depends on Xamarin.Android.Support.Vector.Drawable).
Unfortunately, when I try to run the app on old Android versions (e.g. API 16), I simply get an exception saying android.content.res.Resources$NotFoundException: File res/drawable/splash_screen.xml from drawable resource ID #0x7f020125, with this line at the bottom of the trace: Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector. Removing the <item> with the drawable from splash_screen.xml fixes the crash, but of course there's no logo in the splash screen anymore.
I have also tried adding AppCompatDelegate.CompatVectorFromResourcesEnabled = true in constructor, static constructor, and OnCreate, but no matter where I put it, the result is the splash screen not being shown at all (i.e. the Android app drawer is visible until the app's main screen is shown).
How can I get XML vector drawables on splash screens to work on earlier Android versions?
You could refer to :
https://bugzilla.xamarin.com/show_bug.cgi?id=41489
As #Jon Dick said, it should failed in < API Level 19. In API Level 21, vector support was added to Android, so it works on API Level 21+ with no changes, since the support library would just switch to the native implementation at that point.
Here is an solution : Custom an Android Application, add the AppCompatDelegate.CompatVectorFromResourcesEnabled = true like this :
[Application]
public class MainApplication : Application
{
public static Context AppContext;
public MainApplication()
{
}
public MainApplication(IntPtr handle, JniHandleOwnership transer) : base(handle, transer)
{
}
public override void OnCreate()
{
base.OnCreate();
AppCompatDelegate.CompatVectorFromResourcesEnabled = true;
}
}
Update :
You could use a picture as a background when Android device version is < 21.
Step 1 :
Create a values-21 folder in Resource folder, create a styles.xml :
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<!--
Base application theme for API 21+. This theme completely replaces
MyTheme.Splash from BOTH res/values/styles.xml on API 21+ devices.
-->
<style name="MyTheme.Splash" parent ="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#drawable/splash_screen</item>
<item name="colorPrimaryDark">#1B6698</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>
A Resource/values-v21/ directory contains resources that will be used when the device that is running your app is on API Level 21 or higher. If the device is running on an older version of Android, the Resource/values-v21/ directory will be ignored.
Step 2 :
In your Reources\values\styles.xml, modify the MyTheme.Splash's windowNoTitle with a different background.
Reources\values\styles.xml :
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="MyTheme.Splash" parent ="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#drawable/splash_screen_low_version</item>
<item name="colorPrimaryDark">#1B6698</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>
splash_screen_low_version.xml :
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item>
<color android:color="#3498DB" />
</item>
<item
android:drawable="#drawable/yourlogo"
android:gravity="center"/>
</layer-list>
Please note that, yourlogo is a .png file.
Hello to all programmers. I try to create Android app in Visual Studio Xamarin. I placed EditText in the lower part of app screen and when I set focus on it, keyboard hide bottom part of UI. Is it possible to do something with this?
Screens:
Code:
Main.axml
MainActivity.cs
All help will be appreciated
UPDATED
Theme code:
<resources>
<style name="CustomToolbar" parent="#android:style/Theme.Material.Light">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:colorPrimaryDark">#color/status_bar</item>
<item name="android:statusBarColor">#color/status_bar</item>
<item name="android:colorPrimary">#color/status_bar</item>
</style>
<style name="TransparentStatusBar" parent="#android:style/Theme.Material.Light.DarkActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
<style name="CustomSplash" parent ="#android:style/Theme.Material.Light">
<item name="android:windowBackground">#drawable/splash_screen</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
</style>
</resources>
You can put your layout inside ScrollView. I will allow EditText to be fully visible, but it will not do anything with bottom buttons since they do not block that field.
If you want to make it more pressure for eyes, you can scroll ScrollView when the keyboard is presented on the screen.
EDIT:
To find out when the keyboard appears, you can use GlobalLayout event of the main layout.
ViewTreeObserver vto = element.ViewTreeObserver;
vto.GlobalLayout += (sender, args) => {
element.Height; // will be different with/without keyboard
};
I'm trying to create a new Xamarin.Forms project using Xamarin Studio (6.1.1 build 15. macOS v10.12).
I get a solution with 3 projects. One shared, one for iOS and one for Android. Everything build except the Android one. It fails when trying to compile the resources, specifically the styles file.
The following errors appear:
Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'.
No resource found that matches the given name: attr 'colorAccent'.
No resource found that matches the given name: attr 'colorPrimary'.
No resource found that matches the given name: attr 'colorPrimaryDark'.
No resource found that matches the given name: attr 'windowActionBar'.
No resource found that matches the given name: attr 'windowActionModeOverlay'.
No resource found that matches the given name: attr 'windowNoTitle'.
Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.Dialog'.
No resource found that matches the given name: attr 'colorAccent'.
I tried to remove all Android support related libraries and Xamarin.Forms itself and add them again with NuGet. But that didn't help.
The Xamarin.Forms version I'm using is 2.3.2.127.
Maybe someone can help me out here?
Edit:
This is the file where the errors occurs. I didn't change anything. This is what Xamarin generated.
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="MyTheme" parent="MyTheme.Base">
</style>
<!-- Base theme applied no matter what API -->
<style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
<item name="windowNoTitle">true</item>
<!--We will be using the toolbar so no need to show ActionBar-->
<item name="windowActionBar">false</item>
<!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette-->
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#2196F3</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#1976D2</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">#FF4081</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight and colorSwitchThumbNormal. -->
<item name="windowActionModeOverlay">true</item>
<item name="android:datePickerDialogTheme">#style/AppCompatDialogStyle</item>
</style>
<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#FF4081</item>
</style>
</resources>
I also removed all packages and re-added Xamarin.Forms. It automatically adds the required support packages. But the error still occurs.
I solved this by downloading android_m2repository_r29.zip repository from https://developer.xamarin.com/guides/android/troubleshooting/resolving-library-installation-errors/ with instruction given in same.
I recently changed one of my activity class from inheriting ActionbarActivity(because this class is now obsolete in new android version) to AppCompatActivity. I could specify the icon i want the navigation drawer to use before the change, but after the new ActionBarDrawerToggle doesn't allow that.
I was able to implement this and display the drawer icon, the issue I'm having now is how to change the color of the icon(the three lines icon) from black to white.
The colors of the items in the toolbar depend on the theme.
If you are using Theme.AppCompat (the dark theme) the icons will be white. If you are using Theme.AppCompat.Light the icons will be dark. There is also Theme.AppCompat.Light.DarkActionBar.
More about using the appcompat library.
This is an example for using Theme.AppCompat.Light.DarkActionBar (Light theme with dark action bar and white icons in the actionbar)
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="theme">#style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>
The colour of the ActionBarDrawerToggle can be changed to any colour you want.
Please see an example below:
styles.xml
<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>
<!-- ActionBarDrawerToggle colour -->
<item name="drawerArrowStyle">#style/DrawerToggle</item>
</style>
<style name="DrawerToggle" parent="#style/Widget.AppCompat.DrawerArrowToggle">
<item name="color">#color/my_super_colour</item>
</style>
<color name="my_super_colour">#00ff00</color>
</resources>