Fonts are not recognized at Android Studio - java

My Android Studio doesn't recognize fonts in .ttf or .otf format.
I searched for them at File--> Settings -->File Types , but there i can't find a category which recognizes this formats...
Am I alone with this problem?
Because of my new Membership I can't upload any pics, so here a link to a picture of my problem

It is common for android studio (even in latest version) . I also have "?" mark in project explorer, however it is not problem in programming.

You can use your custom fonts directly in java.
First get a reference to the TextView displaying the text that you want to apply your custom font to. Then call the TypeFace class’s createFromAsset() method to create a new type face using your custom font. You pass an instance of the app's AssetManager as the first parameter by calling getAssets(). This enables you to access the custom font asset file which you pass as the second parameter.
Finally, call setTypeFace() to apply your custom font to the text.
TextView textViewCustom= (TextView)findViewById(R.id.textCustomViewFont);
Typeface custom_font = Typeface.createFromAsset(getAssets(),"fonts/xyz.ttf");
textViewCustom.setTypeface(custom_font);
Android custom fonts tutorial TypeFace java
Create a new TypeFace using your custom font, xyz.ttf which is saved in the assets/fonts folder. You can do it in XML also.

Related

How do I access an image as a Drawable in AndroidStudio?

I'm working on an android app using java in AndroidStudio. I have an ImageView pic and I want to set its image as a .png that I have saved in my /drawable folder. I may try
pic.setImageDrawable(R.drawable.image_name);
However, setImageDrawable() requires a Drawable, while R.drawable.image_name returns an Integer (the ID of the image).
How may I resolve this?
You can use setImageResource() for this:
pic.setImageResource(R.drawable.image);
More about it here
Use this for java
ContextCompat.getDrawable(getActivity(), R.drawable.drawable_resource_name);
and then set this drawable to your image view

Bold textStyle attribute of textview in xml is not working after applying custom fonts in app Android

Bold textStyle attribute of textview in xml is not working after applying custom fonts in app
I have completed developement of an android app. Now I have to change font family for whole app. I have used baskerville-old-face.ttf fonts and used Calligraphy library to apply these fonts into my app.
Following is dependency I have used:
compile 'uk.co.chrisjenx:calligraphy:2.2.0'
Following is the code to initilize Calligraphy library:
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder().setDefaultFontPath("fonts/baskerville.ttf").setFontAttrId(R.attr.fontPath).build());
And following is the code I have used in each Avtivity to use custom fonts:
#Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}
It is working fine and all fonts are changed but there is only one problem that text style (bold) is not working with xml attribute. I don't want to change each textview attribute programmatically (Using JAVA code) because there are more than 100 text views in my whole app.
I am not getting what I am doing wrong or what I am missing. Please help !
Your help will be highly appreciated. Thank you.
I am not sure that this is the best answer but I was seen same problem. you can use the baskervilleBold.ttf font in your code instead of baskerville.ttf if there is exist.

Custom font in pdfjet android

Hi I recently downloaded the open source version of pdfjet that is offered on their website I extracted the downloaded zip and copied the java files found in the com\pdfjet folder to android studio next to my MainActivity.java. I tried a couple of examples that uses some of the corefonts and it works flawlessly but When I want to embed a custom font for the text it won't work on android studio.
I searched on the Internet for a solution but the only solution I found is this:
Font f2 = new Font(pdf,
new BufferedInputStream(getClass().getResourceAsStream(
"fonts/DroidFonts/DroidSerif-Italic.ttf")),
CodePage.UNICODE,
Embed.YES);
From:
http://pdfjet.com/java/examples/example-07.html
But android studio output an error
like in this image:
https://i.stack.imgur.com/W3SPG.png
Any possible solution?
Note: I am using the open source version and I want to use it in Android application
Thanks in advance :-)
They did change their constructor. Just remove "CodePage.UNICODE" part.
protected final Font getFont(String fontName, PDF thePdf) throws Exception {
InputStream fontStream = context.getAssets().open(TypefaceContainer.getFontPathFromName(fontName));
Font result = new Font(thePdf, fontStream, Embed.YES);
return result;
}

Cannot replace android library project resources with android application resources

In my android library project, I have:
/res/drawable/redButton.png
And I reference this image file in my library like this:
public class MyLibExample{
.....
RadioButton r = new RadioButton(context);
r.setButtonDrawable(com.mylib.R.drawable.redButton);
}
Now, in my android application project, I have the same res:
/res/drawable/redButton.png
However, this redButton.png is a different graphics file than the one defined in the library.
I do not reference redButton.png in my application. Instead, I just create an object of type MyLibExample which was defined in the library.
I expected to see the redButton.png from the application, not from the library. However, the redButton.png from the library is always used.
How do I force the MyLibExample to use the redButton.png from the application?
The problem is that the id com.mylib.R.drawable.redButton is the id defned in mylib. You need the id defined in my app. So in your app code:
RadioButton r = (RadioButton)findViewById(com.mylib.R.id.radiobuttonId);
r.setButtonDrawable(com.myapp.R.drawable.redButton);

adding more textviews for every xml tag on android

i'm pretty new to android programming and i'm try to read an xml file. that all works fine, and i can see in the logCat that he is receiving all the data but the app only shows 5 of the tag from the xml file. so i was wondering if i could add some sort of string that will add a new textView/listView or what ever view i need.
There is a good Android API guide on this:
http://developer.android.com/guide/topics/ui/layout/listview.html

Categories

Resources