Font asset not found Android - java

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.

Related

How to access or reference assets from Unity's Assets folder in Android plugin library?

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?

how can fixed this font_subtitle.otf

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

create folder with app icon instead of default folder icon

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

change the default image for the start libgdx app

I'm trying to figure out how to change the following image on start app with LibGdx framework.
I would like to customize it with my logo , but I can not find the reference in the solution .
Thanks for your help.
For IOS platform you should add in your ios/assets folder your own splash images in all resolutions with defined naming structure of Apple.
"Default.png" - 320x480 iphone3gs
"Default#2x.png" - 640x960 iphone4
"Default~ipad.png" - 768x1024 ipad
"Default#2x~ipad - 1536x2048 ipad retina
...etc
more details you can find here ..
Libgdx project for iOS displaying libgdx splash when compiling through robovm on simulator?
In windows explorer go to <path to your project>/desktop/assets
You'll see the default LibGDX image and here you can put all of your assets files (images, fonts, etc). You may also need to refresh your project folders in Android Studio so that the new image(s) will show up.
The java file that loads the image is under the core/src folder. Open this file and you will see where it loads the default image. Change the name of the image to the name of your new image and that should do it.
NOTE: If you are planning to build for android also, android will only see assets that are located in the android/assets folder (it's annoying, but this is the only way it works). I don't use Android Studio, but look up how to set the working directory for your desktop project to use the android/assets folder (instead of desktop/assets). Then put all of your images into the android/assets folder. This one took me a while to find out when I first started building for android. So if your desktop build works, but android doesn't...this is what you need to do to fix it. :)
1)for android, go to asset folder and paste your image
2)Refresh the asset folder
3) in your create method
//libgdx.png is the default image name that provided by the libgdx
texture = new Texture(Gdx.files.internal("data/libgdx.png"));
//in above code remove that "libgdx.png " and add your image name
Example:-
texture = new Texture(Gdx.files.internal("your image name.png"));

Eclipse emulator isn't running up to date version of android app

I'm using eclipse, and my app is at a point where there is a background, and when I run the emulator it doesn't have the background. It had done this before where I changed some text, but when I ran the emulator the text stayed the same. If someone could tell me what I am doing wrong then that would be great. Thanks.
I have noticed that changes made to xml files sometimes do not show up unless you do Project > Clean...
i tried the layout it works fine. You create a folder named as drawable similar to drawable-hdpi. Put your image inside the drawable folder. It work fine.
or
Blockquote
Another option about the problem is that you created you Emulator in such a way that the Android OS determines its screen as xhdpi. If an image is placed in drawable resource folder then Android will try to rescale it for the different resolutions. However if the image appears only in some of the resolution folders (lie drawable-ldpi etc) then the image will be served only in this resolutions.
Please, either create folder drawable-xhdpi and place the image also there, or create folder drawable and place the image there. It will be used for backup.
See the documentation about the image folders: http://developer.android.com/guide/practices/screens_support.html

Categories