I have been making a Digital Clock App Widget, and I have a font I'd like to use, however I can not make a custom View. Tried it, seems like it is not intended to work in a widget(I found out later that I can't use custom views in widgets). And I would really like to have that font, any suggestions?
Related
I wanted to create a custom text view. A little bit advance just as the text editor found here in StackOverflow, I can insert text and even images. I wanted to name this as WordView and create this as a library so I can reuse this across multiple projects.
Unfortunately I am not so sure if the base class allows this. I need a way to insert/paste images directly in the EditText. I am planning to write a custom View, although it seems laborious, I am not quite certain if this is possible at all and if I am going into the right track.
Have anyone tried similar before?
According to the Android Documentation for a TextView You can have a drawable object inside the TextView in the following ways
DrawableBottom
DrawableEnd
DrawableLeft
DrawableRight
DrawableStart
DrawableTop
There are other methods you can use, check out:
1. Programmatically set left drawable in a TextView
2. How to programmatically set drawableLeft on Android button?
3. http://androidsbs.blogspot.co.za/2013/12/androiddrawableleft-set-drawable-to.html
You could possibly implement this using HTML. I'm not sure about the paste functionality but generally it might work.
I know we can use Textview.setTypeface to set a custom typeface (ttf file from assets folder) on a Textview programmatically but i wanted to know is there any way to take advantage of this feature in Android Studio's Edit Mode when we're developing the UI with XML ?
I tried to extend Textview class and setting the custom typeface in constructor but the result in edit mode was the same.
It's working perfect when you're running the app on a real device but it gives a better experience to developer when he is developing the layout and see the exact result at the same time.
i wanted to know is there any way to take advantage of this feature in Android Studio's Edit Mode when we're developing the UI with XML ?
Not in standard Android, as there is no XML attribute for associating an arbitrary Typeface. You can use a third-party library like Calligraphy that offers this.
setting the custom typeface in constructor but the result in edit mode was the same
The editor does not necessarily have access to the typeface and so therefore will not show it in the preview. Now, in theory, a custom widget could do something in isInEditMode() and attempt to handle this, but I have no idea how practical that would be.
Custom typefaces are not supported by the layout rendering library currently. You can star the issue to be notified of updates.
http://b.android.com/27321
There are many ways to use typeface correctly in android, you have to put your typeface file in assets folder under your main directly and can use it run-time.
Other simplest way is use default library to set typeface in your xml file. I have prefer this custom typeface library to set typeface to TextView, EditText, Button, CheckBox, RadioButton and AutoCompleteTextView and other wedget in android.
link: https://github.com/jaydipumaretiya/CustomTypeface/
I have found step by step information with images and code to use my typeface in android project.
I need to get all views that have text for setting custom fonts.
I can develop a recursive method in myBaseActiviy class for getting all views with checking instanceof when programme is in OnCreate(). But I worry about the performance? I interest your idea? What should I do?
There is no best way. An approach, the one I use, is to subclass TextView, adding a new attribute to specify the font I want to use, delegating the logic to the subclass self.
I think the easiest way is to create your own TextView. It's not as hard as it sounds ;-).
This is the origional answer:
https://stackoverflow.com/a/19679639/2767703
And this is the link you'll need:
http://javatechig.com/android/using-external-fonts-in-android-view
Or if you want to set the font in the xml:
https://stackoverflow.com/a/7197867/2767703
Warning
If you are developing for Android versions lower than Android 4.0 then
you should change the code. In these versions there is a bug that
doesn't free up memory for typefaces. What you should do is create a
HashMap that allows reusage of Typefaces. You can find more in the
comments of the last link (search for the comment with the highest
upvote).
You could also use this:
https://stackoverflow.com/a/16883281/2767703
This changes the font of every text in your application. Note: You still have to look at my warning if you use this.
You can do something like this:
Add new attribute for store font in style.
Extend your view to handle this attr and set font by view when do you need.
You can find example of using and creation of new attribute for font at this link https://stackoverflow.com/a/12282315/2156937
Hope it helps.
Is there a way to support more than standard three available text weights in Android. I need to have five: ExtraLight, Light, Normal, Medium and Bold.
I saw this question: How to change fontFamily of TextView in Android, but it related to family rather than weight.
If there is no in-build support, maybe any external resources or libraries are available?
As I am not aware of how a library could add support for your font without including it, I would advise you to create your own implementation of TextView to handle that, it can be done quite quickly, if you only need it for TextView (you would need to implement your own EditText as well if you need that widget).
You can start by looking at the RobotoTextView library which allows for the RobotoTextView widgets to be used in code as well as directly in xml, using attributes.
Is it possible to do something like the following?
<LinearLayout android:id="#android:id/empty"
android:background="?android:style/Widget.ListView.overScrollFooter"
>
Left out all the unimportant layout stuff. I'm wondering if it's possible to reference one of the individual attributes of defined in a style?
Edit for more info: The default styles and attributes for many widgets are defined by Android, and customized further by phone manufacturers. That's how they can customize how a basic android widget looks. In my example, the footer of a listView will look different on a Samsung phone than on a HTC phone or on a default Google phone.
I would like to grab the attribute defined in the listview style (specifically the overscrollfooter drawable attribute), and use it as a background for one of my views. Technically speaking, I have a programmatic solution for this, but it's clunky, and requires that I repeat that code every time I use this view (which is in a lot of places).
No, I think a style is an all or none kinda of deal. I would place the footer in it's own style and import it into your primary style. That frees it up to be used (alone) in yout LinearLayout.