I have created an empty Nativescript application with tns create myApp'. However,app/App_Resources/Android/drawable-hdpi` and other directories does not contain any default system icons. Thus, I cannot use them in the application. How can I find or install default system icons?
However, the default system icons are called using something like this:
<ActionItem ios:systemIcon="12" android:systemIcon="ic_menu_search" tap="showSearch" ios:position="right" android:position="actionBar" />
You can find a list (unfortunately without images) at https://developer.android.com/reference/android/R.drawable.html
For using your custom icons in the application, you have to add them in each drawable-XXX folder and then in your XML src="res://my_icon"
You can find more informations in the official documentation of NS : https://docs.nativescript.org/ui/ui-images#load-images-from-resource
Related
I would like to create settings page which would look like the settings on native platform (eg. PreferenceActivity/Fragment with xml on Android).
I am used to design the settings page by creating simple preference xml on Android which handles the basic settings flawlessly, however I am unable to find the similar mechanism in Xamarin.Forms which would do the same thing for all platforms natively (with the gui part). I just only found the SettingsPlugin which handles "Create and access settings from shared code across all of your apps!".
https://github.com/jamesmontemagno/SettingsPlugin
I would really appreciate any recommendation on designing the settings pages.
You can use a TableView, which is an original Xamarin Forms User interface (without any plugin).
If you set his Intent="Settings" , you can display a nice list of configuration settings like SwitchCell, EntryCell, or a CustomCell.
Displaying these elements depend on the operating system and on the version of it. So it looks and feels different on f.e. Android 4.4 and different on Android 8.
For example:
<TableView Intent="Settings">
<TableRoot>
<TableSection Title="My settings">
<EntryCell Label="Name:" Placeholder="Enter Your First Name Here"/>
<SwitchCell Text="Show my name" On="true"/>
<SwitchCell Text="Update app automatically"/>
</TableSection>
</TableRoot>
</TableView>
Which will render something (not exactly that) like this: {source of img}
I am trying to use icon font FontAwesome in Nativescript application, which is possible according to this article https://www.nativescript.org/blog/mobile-app-best-practices---use-font-instead-of-image-to-show-an-icon
I did everything that is described in that article:
Added .ttf in app/fonts
Added class in app.css
.fa{
font-family: "FontAwesome";
}
Used it in XML like so
text="" class="fa"
But result is rather disappointing:
I also tried the "\uf230" syntax, but that renders as plain text.
What am I doing wrong?
Could be a few things. Does it work on iOS? As your CSS definition is iOS compatible, not Android as Android needs the actual filename (without extension) whereas iOS needs the font name. So I have this to be xplatform-ready (the file is 'fontawesome-webfont.ttf'):
.fa {
font-family: 'FontAwesome', fontawesome-webfont;
}
The \f005 syntax is OK (<Label class="fa" [text]="'\uf005'"></Label>), but I'm using the splendid nativescript-ngx-fonticon plugin (there's also a non-Angular one) to be able to do this instead:
<Label class="fa" [text]="'fa-shopping-basket' | fonticon"></Label>
To make it work, you must make sure that the "fonts" directory is inside the "app" folder and that the following files exist:
font-awesome.eot
font-awesome.ttf
I opted to adopt this font as the default of my application, so I do not have to worry about where I'm going to use it and how much to enter the right class, everything is getting very good and the result is perfect.
In CSS, you only have to define a selector according to your interest for the source to be used, so just use the directive:
page {
font-family: 'FontAwesome'
}
Then where you want an icon, just use an html entity that represents it as it searches the site: http://fontawesome.io/icons/
See images:
You can see this video where I was based to start. It corrects in the video the extension used to be attentive.
I am trying to use a custom font on a TextView in Xamarin C#
I have the file coopbl.ttf (don't judge me, this was just to see if it worked!)
I have placed it in the following location root/Assets/Font/coopbl.ttf and marked Build Action to AndroidAssist
My XML looks as follows:
<TheKey.Classes.CustomTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="font"
android:textSize="50sp"
android:id="#+id/customFont"
custom:customFont="Font/coopbl.ttf"/>
When I call Typeface.CreateFromAsset(Context.Assets, "Font/coopbl.ttf"); I get the following exception:
Java.Lang.RuntimeException: Font asset not found Font/coopbl.ttf at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw
I have followed much of the pattern used by Cheesebaron here, including the TextView.cs class: https://github.com/Cheesebaron/Cheesebaron.FontSample.
What have I missed?
Update based on comments
I tried the following with no luck, still seeing the same error:
Renamed Font directory to font then to fonts and then even tried Fonts for completeness
Removed Font/ from the method call
In Visual Studio, the Assets folder is located in the root of the project when a new Xamarin project is created, it is at the same level as Resources.
I've added
<favorite
launcher:className="com.android.gallery3d.app.Gallery"
launcher:packageName="com.android.gallery3d"
launcher:screen="3"
launcher:x="1"
launcher:y="3" />
in res/xml/default_workspace.xml,but the gallery icon was not added.And when adding hotseats it appears the same problem.
Can anyone help me?Thanks a lot.
In the Samsung device you can create /system/csc folder and copy here file default_workspace.xml.
If CSC.apk is available in the /system/app (or /priv-app) folder, all changes in /system/csc/default_workspace.xml must be applied to default homescreen settings.
I have a simple Android app (built with Mono for Android), which has a problem with it's icon.
The icon is correct in Launcher and in Task Switcher, but
In Manage Apps and in Task Manager it's displayed a generic Android icon
I've checked the various density resources and the manifest and they all look correct.
(I'm seeing this on a Galaxy S phone and on a Nexus 7)
Most likely you set the icon property for your activities within AndroidManifest.xml, but did not set it for the application.
It occurs to me, that the app icon is somehow being cached in the app manager, so that deinstalling and reinstalling the app does not always change the icon properly. Rebooting the device could help.
Also i found this post very useful: adding application ids in gradle usually solves the problem.
Open "AndroidMenifest.xml" in the Package Explorer and click on the "Application" tab at the bottom. Look at the "icon" field and enter the location for your icon ( Ex: #drawable/iconimage). Next, go into the "AndroidManifest.xml" tab and look for android:icon=, adding the location to that as well (Ex: android:icon="#drawable/iconimage)
Make sure you have the same icon name in both locations!
Oleg and Collin are both right but for completeness - in a Mono app the icon can be set with attributes on the Application object (if you have one):
[Application(Label = "MyAppName", Icon = "#drawable/icon")]
class MyApp: Application
{ ...