New to Android development. Why is my custom typeface font not showing up in the Type folder? - material-design

I'm pretty new to Android development (especially Jetpack Compose), so I'm sure I'm forgetting something stupidly easy!
I downloaded the custom Montserrat regular and bold fonts from Google (as .ttf files), created a font directory in my resources folder, renamed the fonts to follow naming conventions, dragged the fonts into the font directory, then tried to initialize them in the Type.kt file as a variable named Montserrat. I get an unresolved reference error and the Lint suggestion creates an XML file in the font directory. I have used custom fonts from Google many times before and followed the exact steps, but something is clearly not working!
I'd love to post screenshots, but I do not have enough reputation, unfortunately.
Any help is extremely appreciated!
Followed basic instructions to use custom fonts, and it is not initializing in the Type.kt folder.

If you're using Jetpack Compose to build your Android app, you can specify custom fonts in your app's typography object. You can then use the font property in the Text composable to apply the font to your text. Here's an example
#Composable
fun MyApp() {
val customFont = font(R.font.montserrat)
Typography(
h1 = TextStyle(
font = customFont,
fontSize = 24.sp
)
)
// ...
}
You can then use this style in your app like this
#Composable
fun MyScreen() {
Text("My headline", style = Typography.h1)
}

Related

Load HTML file and display in Flutter Web

I have a single HTML file that contains some JS functions and CSS styling.
Is it possible to load my html file into an embedded widget on Flutter Web? I've successfully accomplished this on iOS and Android using the flutter_webview pacakge, but haven't found a solution for Flutter Web.
There is a HTMLElementView widget which can help you embed Html in flutter web. This widget can take an Iframe and render it. If you don't prefer Iframe then you can embed simply a BodyElement from the dart:html library directly.
An example of embedding Iframe is availabel here. Eventhough its from an old repo, the code is valid and I couldn't find a latest one.
If you don't want do go the tough way, there is simplified widget from Rodydavis which is available here called easy_web_view.
Still if you need code sample a create simple dart pad and share the MRE, I will try to help. :)
For the Iframe example, you can do something like this
First, import 'ui' library, and 'html' library.
import 'dart:ui' as ui;
import 'dart:html';
Second, register your 'Iframe' with viewType 'test-view-type' just for example.
ui.platformViewRegistry.registerViewFactory(
'test-view-type',
(int viewId) => IFrameElement()
..width = '640'
..height = '360'
..src = "https://www.youtube.com/embed/5VbAwhBBHsg"
..style.border = 'none');
Note: you will notice that the compiler can't find platformViewRegistry method but it's okay if you choose to Debug anyway and it will run correctly without any problems.
Finally, use HtmlElementView widget to run this Iframe
return Scaffold(
body: Column(
children: [
Text('Testing Iframe with Flutter'),
HtmlElementView(viewType: 'test-view-type'),
],
));
You can use this package flutter_widget_from_html
While defining the widget you need to set webView: true to get iFrame support
I just tested and it is working fine on web, and this package supports local assets too

Gitpitch creating custom colors

I am starting and creating a gitpitch presentation and it works great.
I want to create a custom color so that I can use it in the presentation
but it does not work.
In the custom.css file, which I now is added correctly since other stuff in there are being displayed I add...
.myblue {
color: #65656c;
}
Then in PITCHME.md I add...
#snap[west]
Create container<br>
#color[#65656c](singularity build)<br>
#color[myblue](Install software)<br>
#snapend
in this example "singularity build" gets the right color, but "install software" does not.
Does anyone have a suggestion?
When you declare a custom style, such as myblue, you can make use of that style by referencing the class as follows:
#snap[west]
Create container<br>
#color[#65656c](singularity build)<br>
#css[myblue](Install software)<br>
#snapend
Note how I used the #css shortcut syntax to activate the myblue class on the Install software text. You can learn about all of the available GitPitch markdown shortcuts in the docs here. And you find specific examples using the #css shortcut syntax right here.

orchard: include font awesome

How I can include font awesome to my module in admin (v.1.10.2.0)?
There is something similar like Style.Require("jQueryUI_Orchard"); ?
Or I need add Add awesome to my project
Orchard.Resources provides a resource manifest for font awesome. Therefore add a reference to module Orchard.Resources and add Style.Require("FontAwesome") to a view to get font awesome included.

Trying to install custom font in xcode 4.2, iOS 5.0, but receiving error "Validation failed: [duplicate]

I want to use font "MgOpen Modata" in my iphone App. But I dont see it in the font list in Property inspector.
How do I include that font so that I can use it?
Add the font files to your resource files
Edit your Info.plist: Add a new entry with the key Fonts provided by application.
For each of your files, add the file name to this array
On the example below, I've added the font "DejaVu Sans Mono":
In your application you can the use [UIFont fontWithName:#"DejaVuSansMono-Bold" size:14.f].
Or if you want to use it in html/css, just use font-family:DejaVu Sans Mono;
Note: this is available in iOS 3.2 and later.
I found this walkthrough was the best
Although the above accepted answer does work I found that if you added text into an XIB file and then set the font to our new font then the text didn't update.
Making sure the new font is included in resources fixed this problem (taken directly from walkthrough):
"This should not be a problem but sometimes when you’re having trouble getting your font face to show up, this can be a source of headache so let’s double check now to rule it out as a potential pitfall.
Go to your project Build Phases pane by highlighting the XCode project file in your solution explorer and on the right hand side, select “Build Phases”. You’ll see that one of the sections you can expand is “Copy Bundle Resources”. Open that list and make sure that your fonts are included in that list."
The other stuff in the walkthrough is the same kind of stuff (add the file to your project and to the plist file too)
All credit to Code with Chris for this answer which saved me a lot of time and effort and I am merely copying a shot from his page to allow this answer to stand on its own feet instead of requiring you to click the link.
I think is better for a dev to have the plist structure as raw source code. I'm leaving it for copy/paste:
<key>UIAppFonts</key>
<array>
<string>Roboto-BoldItalic.ttf</string>
<string>Roboto-Medium.ttf</string>
<string>Roboto-MediumItalic.ttf</string>
<string>Roboto-Regular.ttf</string>
<string>Roboto-Bold.ttf</string>
</array>
Copy this snippet and modify the strings keys into the array to your desired fonts. Hint: To view the plist as raw source code please click secondary button over the file and select Open As -> Source code.
EDIT
// Logs fonts ordered by name
for (NSString* family in [[UIFont familyNames] sortedArrayUsingSelector:#selector(compare:)])
{
NSLog(#"%#", family);
for (NSString* name in [[UIFont fontNamesForFamilyName:family] sortedArrayUsingSelector:#selector(compare:)])
{
NSLog(#" %#", name);
}
}
After adding the fonts could be useful to add to (for example) the AppDelegate.m class to see what are the real fonts names (on the bundle). A problem I encountered various times that I was loading the fonts with a wrong name assuming that the font filename as the correct one. Sometimes it differs from the bundle real name.
In addition to this you can check the file full name using the file info window (cmd+i) on finder (macOS).
Example to clarify:
File Name = "DroidSansEthiopic-Regular"
Processed Name in bundle = "Droid Sans Ethiopic"
Don't forget to add the fonts to the targets compile bundle resources by going to 'Targets' -> 'Build Phases' -> 'Copy Bundle Resources' and add all the fonts manually
Most of the time we forget to add font to the application Target. Make sure you did not forget this important step. Mind checking right panel File Inspector > Target Membership checkbox.
Also you can check wether font is added well to your application or not by running this code snippet in anywhere on your app.
for (NSString* family in [UIFont familyNames])
{
NSLog(#"%#", family);
for (NSString* name in [UIFont fontNamesForFamilyName: family])
{
NSLog(#" %#", name);
}
}
EDIT
ALPHABETIC ORDER:
for (NSString* family in [[UIFont familyNames] sortedArrayUsingSelector:#selector(compare:)])
{
NSLog(#"%#", family);
for (NSString* name in [[UIFont fontNamesForFamilyName:family] sortedArrayUsingSelector:#selector(compare:)])
{
NSLog(#" %#", name);
}
}
This will populate a list of available fonts in your app, where your added font will also appear.
Its Easy and simple now- Tested in Xcode 9.2 and swift 4
Steps to add font to your Xcode
Select your UILabel, UITextField or whatever then under fonts section and follow
Step 1
Select settings menu from left corner of font selection screen. And choose font manager option.
Step 2
Click on the add button as marked below.
Step 3
Select the folder that contains your font. It will be loaded into XCode fonts list.
Steps to add fonts to your project
Don't forget to add description to your plist with the key Fonts provided by application. and put font files inside copy bundle resources under project target settings.
Yes! thats it.. njoy..
You can use [UIFont fontWithName:#"ArialMT" size:14]; method directly, if you want to change your font style. Also all the fonts may not be available in iphone library.Just refer this for available font styles.
If you have .otf format. sometime this format doesnt work. Convert .otf format to .ttf. There are bunch of font converter online.
Once you add the custom font to your .plist file under Fonts provided by application as explained above. Make sure in your Project Target under Build Phase -> copy Bundel Resourse that file is present. If not then add it.
Then just in your code add this [UIFont fontWithName:#"your custom font" size:your choice of size];
In Xamarin iOS
Step 1:
First of all you have to add your .ttf or .otf file into your Project.
like Roboto-BoldItalic.ttf .
Step 2 :
Right click on the Font and select property
Build Action --> Content
Copy to output directory --> Always Copy
Step 3:
go to info.plist
select property Fonts provided by application and add the font name.
Step 4:
set Font programatically below way
account.Font = UIFont.FromName("Roboto-BoldItalic", 18f);

How do I refer to an image using CSS for a Sproutcore app?

All,
Simple question: I want to include an image "logo.png" as the background for my-app. Where should I put the file and how should I refer to it in the CSS file which is in the resources folder along with the main_page.js?
Here is the rest of the story:
I have a CSS class called doc-background. I know this class works because when I set the color of the background in a CSS file like so:
.doc-background { background-color: red} it has the desired effect and Firebug shows me that the class doc-background is being used.
However, when I add a line like
.doc-background { background-image: url('logo.png'); }, there is no effect. Firebug shows that the class doc-background is not applied. And when I modify the style in Firebug to add the line about the background-image it says "Failed to load URL" in the tooltip.
Can someone please point me to a guide on how to work with resources and images and where to put them if I want to use CSS? I have successfully used them using the image-view and coding them into the HTML.
Here is what I have already tried:
Using static-url instead
Moving the image file to images folder under resources
Referred to the image by using all variations on the path - including resources/images only including images, not including either...
Lot of Googling for the answer, Reading create your own app tutorials etc.
If you have an example app that uses colors and images from a CSS that will be the ultimate! But a location and some help with the background-image CSS property will get me started!
Thanks much,
Vis
Place your image somewhere relative to your css:
resources/style.css
resources/images/logo.png
Then use static_url to refer to the image:
background-image: static_url('images/logo.png');

Resources