I am following this tutorial to change the fonts of the app in Xamarin.Android, it is just adding the .ttf file to the project and then referring to the TextView / EditText where you want to use it in the XML, like this:
android:fontFamily="#font/sourcerfont"
The problem I am having is that it only works with virtual devices, and not with physical ones.
I reread the documentation (the tutorial) and found this part that caught my attention, and I get the impression that the error could be there since my physical device has API 23 - Android 6.0.1; and the virtual one has Android 9.0:
This feature is also supported on devices till Android 4.1 by using
Support Library 26 or more.
Could you tell me what I'm doing wrong?
I don't think you can only use custom fonts on Android apps with versions older than 8.
The only way that works for me on all devices is this but it is very tedious with large apps:
TextView Lbl = FindViewById <TextView> (Resource.Id.Lbl34);
tf = Typeface.CreateFromAsset (Android.App.Application.Context.Assets, "quicks.ttf");
Lbl.SetTypeface (tf, TypefaceStyle.Normal);
I reread the documentation (the tutorial) and found this part that caught my attention, and I get the impression that the error could be there since my physical device has API 23 - Android 6.0.1; and the virtual one has Android 9.0
I download Karantina font family, then creating a folder named font under the Resources folder. Put the font file inside it, build action is set to AndroidResource , see the following screenshot:
I use this custom font:
<LinearLayout 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:orientation="vertical">
<TextView
android:text="My text content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/karantinaregular" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="karantina Bold"
android:fontFamily="#font/karantinabold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="karantina Light"
android:fontFamily="#font/karantinalight"/>
I test my code on Android virtual 8.1(API27), Android physical device 8.1(API27) and Android physical device 6.0(API23), it all works, having no problem.
Related
I am trying to create a Binding class in Visual Studio like in Android Studio https://developer.android.com/topic/libraries/data-binding/generated-binding
What I have:
Visual Studio 2022 17.4.5
Xamarin 17.4
What I've done:
Create Android App (Xamarin) project. Blank App and minimum android version 10.0
install Xamarin.AndroidX.DataBinding.ViewBinding 7.4.0.1 nuget package
Adds to the .csproj file
<AutoGenerateLayoutBindings>true</AutoGenerateLayoutBindings>
Adds a root element to activity_main.xml
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/hello_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, world!"
android:textSize="24sp"
android:layout_centerInParent="true" />
</RelativeLayout>
</layout>
Build project. In output window
Rebuild started...
1>------ Rebuild All started: Project: App4, Configuration: Debug Any CPU ------
Restored C:\Users\koly8\source\repos\App4\App4.csproj (in 73 ms).
1> App4 -> C:\Users\koly8\source\repos\App4\bin\Debug\App4.dll
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
nothing have been created
Maybe missed something
I tested the code you provided but failed, then refer to the doc: Data Binding Library. It said:
To configure your app to use data binding, enable the dataBinding build option in your build.gradle file in the app module, as shown in the following example:
android {
...
buildFeatures {
dataBinding true
}
}
The dataBinding library is actually part of the gradle build toolkit so isn't available in Xamarin.Android applications. For xamarin android the most recommended way is to use data binding is to use the native libraries, for example MVVMCross.
I'm making one portable xamarin application, and i'm using XFGloss. Everything is working fine on Android and iOS, but on WinPhone 8.1 my BackGroud Gradiant still black.
My page has:
<xfg:ContentPageGloss.BackgroundGradient>
<xfg:Gradient Rotation="150">
<xfg:GradientStep StepColor="#305E70" StepPercentage="0" />
<xfg:GradientStep StepColor="#305E70" StepPercentage="1" />
</xfg:Gradient>
</xfg:ContentPageGloss.BackgroundGradient>
On, Android and iOS i should initilize xfgloss, like this:
-Android
XFGloss.Droid.Library.Init(this, bundle);
-iOS
XFGloss.iOS.Library.Init();
And i dont found how to init XFGloss on WinPhone, even know if have to init this.
How to make this works on WinPhone?
XFGloss has no support for Windows. I guess it would never support WP8, but sometimes it may get support for UWP. At least there is issue for that
I've been following:
https://developer.xamarin.com/guides/android/platform_features/maps_and_location/maps/obtaining_a_google_maps_api_key/
and
https://developer.xamarin.com/guides/android/platform_features/maps_and_location/maps/obtaining_a_google_maps_api_key/
in order to use Google maps in an android app. And I cannot get the maps to show in my application at all. It always shows a blank page. I'm also not seeing any errors.
I have:
Added the necessary permissions to my android manifest
Enabled the API in the apis page online.
Added credentials based on using the local debug keystore
Added the map as a mapfragment on my main activity page.
Everything online is pointing at the debug key being incorrect but I must have tried everything I can with this one and it still doesn't work. Could it be picking a different one up somehow?
Also, I'm not sure of the significance, but the mapfragment is always null in on resume when I try to access it.
Keystore command:
keytool -list -v -keystore "C:\Users\<My User folder>\AppData\Local\Xamarin\Mono for Android\debug.keystore" -alias androiddebugkey -storepass android -keypass android
Permissions in manifest (With AppName and key hidden):
<!-- Google Maps for Android v2 requires OpenGL ES v2 -->
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<!-- We need to be able to download map tiles and access Google Play Services-->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Allow the application to access Google web-based services. -->
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- Google Maps for Android v2 will cache map tiles on external storage -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Google Maps for Android v2 needs this permission so that it may check the connection state as it must download data -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Permission to receive remote notifications from Google Play Services -->
<!-- Notice here that we have the package name of our application as a prefix on the permissions. -->
<permission android:name="APPNAME.permission.MAPS_RECEIVE" android:protectionLevel="signature" />
<uses-permission android:name="APPNAME.permission.MAPS_RECEIVE" />
<!-- These are optional, but recommended. They will allow Maps to use the My Location provider. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application android:label="<app name>">
<!-- Put your Google Maps V2 API Key here. -->
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="MYKEY" />
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
</application>
Main activity contents:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
in order to use Google maps in an android app. And I cannot get the maps to show in my application at all. It always shows a blank page. I'm also not seeing any errors.
This is probably caused by following reasons:
Check the reference here How can I create a keystore?
Once the app is signed then the map won't work.
When you use a different computer to build the app please get the SHA-1 from the new computer.
Do not use the keystore that is generated by Java. Please use the keystore that is generated by Visual Studio. It is in C:\Users\username\AppData\Local\Xamarin\Mono for Android/.
Use the emulator that contains Google API.
Do not forget to enable Google API in Google Console.
And this Xamarin Android Google Map demo should be helpful for you. I have tried this demo with my own keystore and API_KEY and it works.
I have solved this problem by configuring my project in Google Console to Enable
Places SDK for Android
And
Maps SDK for Android
wait for few minutes and BOOM !
Sometimes you might need to reinstall the app on your device.
If you enable Google Play App Signing then you need to use the keystore detail that will be provided by after you have uploaded your apk.
Release management -> App signing (tab)
App signing certificate is what you need. Copy the SHA-1 certificate fingerprint.
The current answer didn't quite work for me. I misunderstood what the docs -https://learn.microsoft.com/en-us/xamarin/android/platform/maps-and-location/maps/obtaining-a-google-maps-api-key?tabs=windows - meant when it says:
This API KEY must be the API KEY from the google developer console and not the SHA-1 that you used to generate your keystore. While this might have been obvious to most of you, hopefully this helps some other user in the future.
Just for collection..
I faced with the same problem but after load my bundle file application through the Google Play Console...
I signed my application by my release keystore key and ... nothing. maps doesn't appeared in application downloaded and installing from Google Play.
So solution is in this archive topic (in the last post):
https://social.msdn.microsoft.com/Forums/en-US/ef283f57-676a-498a-afa6-74ac237391f1/google-maps-blank-on-release-mode?forum=xamarinandroid
"In my case, it turned out that Google Play Console signed the released apk with its own Google certificate, setting a SHA1 different to the one used to authorize the Google Maps API."
It's exactly weird... but any way.. After i download my app from bundle explorer and check SHA1 I was "surprised"... Just added this "new" SHA1 in my Google Cloud Platform for my "Restrict usage to your Android apps" section.. And Maps appeared for all versions..
That's all.
I will be glad if it help someone
Since I built a new computer I'm having problems running my current project on every emulator I could think of (e.g. Xamarin Android Player, Visual Studio Emulator, the Android SDK one ...). Every time I run the project on an emulator (it works on real devices just fine) the emulators screen is gray and only some text rendered by my "engine" appears.
(like this: http://i.stack.imgur.com/7AFos.png ). To develop my project I'm using Xamarin and OpenGL ES 2.
I've looked up all the logs from the different emulators and there are only a few differences when debugging on an emulator and a real device.
The log shows some crazy opengles errors
I/OpenGLRenderer( 3523): Initialized EGL, version 1.4
W/EGL_emulation( 3523): eglSurfaceAttrib not implemented
W/OpenGLRenderer( 3523): Failed to set EGL_SWAP_BEHAVIOR on surface 0x9c242f20, error=EGL_SUCCESS"
There are quite many garbace collections (around one every second) whichs log look like this:
D/Mono ( 3523): GC_OLD_BRIDGE num-objects 1 num_hash_entries 1 sccs size 1 init 0.00ms df1 0.02ms sort 0.01ms dfs2 0.01ms setup-cb 0.01ms free-data 0.01ms links 0/0/0/0 dfs passes 0/0
D/Mono ( 3523): GC_MINOR: (Nursery full) pause 0.51ms, total 0.73ms, bridge 0.01ms promoted 1216K major 1216K los 331K
Here is my Android manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.tipfom.mapknight">
<uses-feature android:glEsVersion="0x00020000" />
<uses-sdk android:targetSdkVersion="21" android:minSdkVersion="21" />
<application android:label="mapKnight" android:icon="#drawable/icon" android:hardwareAccelerated="true"></application>ยด
I've allready tried to turn off Host GPU, increase the target and minSdkVersion of the Application, Download all AndroidSDK files till API 15 and install the Intel HAXM driver.
I've been having issues with using Ads on xamarin for android, was hoping someone with more expertise could offer some advice.
This is the first App I have build using Xamarin Android, or at least attempted to. Within the layout I have left a space for an advert.
I've followed multiple guides including;
How to integrate AdMob ads in the latest MonoGame Android (XNA)?
https://blog.tommyparnell.com/admob-with-xamarin-part-1-banner-ads/
Both guides I've followed to the letter and I'm getting the same error each time I try to run the application
The syntax in my main activity is as follows;
AdRequest adRequest = new AdRequest.Builder().Build();
layout.LoadAd(adRequest);
When this is included, I get a runtime error as follows;
Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an instance of an object
06-05 09:39:21.062 E/AndroidRuntime( 7212): at MyApp.Android.MainActivity.OnCreate (Android.OS.Bundle) [0x00028] in c:\Users\User\Dropbox\Projects\MyApp_Xamarin\MyApp.Android\MainActivity.cs:44
I have tried deleting and recreating the google play services reference.
I've ensured my manifest has the relevant activity tags within it
<activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
I'm at a total loss. The error I'm receiving looks like a java error, although as I'm in the c# environment I can't directly access and debug this that I can tell.
After 3 days of getting no further with this issue I've turned to StackOverflow, if anyone can point me in the right direction I'd be very grateful!
I am using visual studio 2013
Cheers.
I've added admob to a Xamarin Forms app but not an XNA game. Here is a link to my app on github
var adMobElement = Element as AdMobBuddyControl;
if ((adMobElement != null) && (e.OldElement == null))
{
AdView ad = new AdView(this.Context);
ad.AdSize = AdSize.Banner;
ad.AdUnitId = adMobElement.AdUnitId;
var requestbuilder = new AdRequest.Builder();
ad.LoadAd(requestbuilder.Build());
this.SetNativeControl(ad);
}
Make sure to have this in your application tag of manifest:
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
And this permission:
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
I kind of fumbled my way through it. You may not need everything that I mentioned but hopefully it can give you a starting point.