how a can fixed Error:Error: The file name must end with .xml or .png
Your problem is the fact that you have put a file of type .otf into a folder than only accepts .xml or .png (res/drawable is a folder you only put pictures and drawable resource files into).
Put that font_subtitle.otf file into a fonts folder. Your fonts folder should already be made for you in app -> src -> main -> assets -> fonts. But if not just make one and put your file in there.
Also, I assume that you might not know how to use the file once it is in your assets folder, so I will just include some code showing an example of how to use the file.
Typeface eightBitFont = Typeface.createFromAsset(getAssets(), "fonts/custom.TTF");
topText.setTypeface(eightBitFont);
In this example, I create a Typeface object and create a custom font from my file. I then use my topText object (which is a TextView) and set the type face using setTypeface and use the name I gave my object in the line before.
If you are trying to use the new Fonts in XML feature added to Android O - 8.0 (API 26), you definitely can add font files (.ttf, .ttc or .otf) to the \res\font folder.
You probably need to upgrade to Android Studio 3.+ and build tools 3+ to get it to compile properly without the error.
Also, take a look at this post: Font in XML with Android O
Related
I have a font that I am using to design and edit scenes in Unity. I am having an android plugin library that displays native AlertDialog in android. I want the dialog to display message using same font I use in Unity. I have placed that font in Unity's Assets/Fonts folder. I know that when font is used in any scene, it gets copied to final build apk. Now I want to access the same font and Android plugin's Java code. How can I achieve this
Here is the Java code
Typeface typeface = Typeface.createFromAsset(mainActivity.getResources().getAssets(), "Fonts/lobster-regular.ttf");
I know my path is wrong, what is the correct way of referencing font placed inside Unity's Assets folder from Android plugin's Java code.
Also I had tried placing font in Unity's StreamimngAssets folder and I was able to call that font using createFromAsset(mainActivity.getResources().getAssets(), "fonts/lobster-regular.ttf"). But the problem is that in this method I cannot use the font in Unity Editor while editing Scenes as font is placed in StreamingAssets folder.
So how can I reference Font placed in Assets folder from android plugin's Java code?
I have got a project (implementing Sceneform) that contain sfb files in the raw folder.
I want to copy/past these sfb files to another project. But when I paste them, the content is no more readable even if the file is ok in the 3D preview window.
How to copy/paste a .sfb file from one project to another ?
Ok, found the solution. You have to create a sampledata folder like explained here: https://developers.google.com/ar/develop/java/sceneform/import-assets
And copy/paste also all your sfa, fbx, bin, etc.. files here.
And then the text in the sfb file will become readable.
When I try to programatically set custom font from .ttf file in assets to button in my android app it returns error Caused by: java.lang.RuntimeException: Font asset not found fonts/menubutton.ttf.
Assets folder is in main directory, and I use this code:
Typeface tpf = Typeface.createFromAsset(this.getAssets(), "fonts/menubutton.ttf");
benterday.setTypeface(tpf);
How can I repair this error?
There is a new way to accomplish this:
put your_font.tff under app/src/main/res/font
create Typefaces using Typeface font = ResourcesCompat.getFont(context, R.font.your_font);
access font from xml layouts with android:fontFamily="#font/your_font"
source
This could be due to a number of issues. Please see which one works!
The font file is corrupted. Please see whether the app works with another standard ttf font.
Sometimes Android Build studio shows up bugs. Try cleaning the project and building again.
Verify the font folder and the font file name (no spaces etc.)
There is 2 ways to add fonts in android studio.
first way: right click on you app folder and choose:
app->New->Folder->Assets Folder
then in newly created folder right click and then selected "New->Directory" and set the name to "fonts".
now you can add your fonts here and your problem would be fixed.
second way is #andreaciri way that works in newer versions of android studio.
I want to add my app Icon to created folder instead of default folder icon.
I know i can create folder with following code.
String extr = Environment.getExternalStorageDirectory().toString();
File mFolder = new File(extr + "/My Application/Downloads");
if (!mFolder.exists()) {
mFolder.mkdirs();
}
By doing this, i'm getting following result.
but what i want is..
I have searched a lot, but no luck. can anyone help me out?
Thank you.
Directories do not have icons, and so whatever app or tool your screenshot is from is adding that. You would have to ask the developers of that app or tool what algorithm they are using to determine the icon to show.
Customization of folder icon is OS dependent.
On Windows you will use Desktop.ini file to assign a custom icon or thumbnail image to a folder. To simplify working with Desktop.ini you can use ini4j. Basically, you will need to create Desktop.ini in the folder, that you want to customize and specify path to the icon there. (Here is similar question)
On Mac OS the process is different. There are ways to access icons (for example, FileView or FileSystemView, also Quaqua). However I haven't found a way to set folder icon programmatically with Java.
Note: I assumed, that you want to add icon to arbitrary folder and not your app laucher.
After creating new directory you have to declare resource directory in your gradle file so that android studio can recognize new resource directory.
More information please refer https://developer.android.com/studio/write/add-resources
In my drawable folders i have my icon image, and when testing i use it as a temp picture. I added 2 other images and a XML file and when ever the app loads the imageviews with the icon set to it has different images..
this is what it is meant to be be..
but this is what it is when i add other images to the drawable folder
And no, the names of the files are not the same.
The icon is called 'icon.png' - thats what it should be
instead it is 'ic_menu_compose.png' - a completely different name.
Also the files i'm adding are called:
'buttonnormal.png'
'buttonclicked.png'
and a XML file - 'buttonselector.xml'
Even if i dont use these images any where within my app the problem still occurs.
Any help would be much appreciated. Thanks! :)
[EDIT]
Are you building your app inbetween tests?
In eclipse: Project > Build Automatically (ticked) (this regenerates your R file)
Are you referencing the image by a raw ID?
setImageResource(324234234); WRONG
setImageResource(R.drawable.blah); Right
Are you using drawable image names that are already in use by the Android system: http://androiddrawableexplorer.appspot.com/
Personally I would rename that images from "ic_menu_compose" to something like "icon_menu_compose_overwritten" just incase it is clashing and screwing up your R file.