Android Font Change - android

I am trying to create an android app that will change the font at the push of a button. I have searched through stackoverflow and other sites on Google, but have come up empty handed. I am using Eclipse. The goal is to be able to simply touch a button that reads "times new roman" and then have the text above change to that font. I found people trying to change the font in Eclipse, or simply the default font for their app, but not have the user be able to change it. I got this idea after finding an app that changes background colors. Does anyone know what code I need for the buttons?

Typeface is what you are looking for.
In the onclicklistener of the button, try something like
TextView txt=(TextView)findViewById(...);
Typeface tf=Typeface.createFromAsset(...);
txt.setTypeface(tf);

Related

Dynamic colours in an app

I have colors of text and button come dynamic form backend,
I need to change this color of text dynamically when change happens in backend all at time.
I could make it manual
textView.setTextColor(getResources().getColor(R.color.text_color));
Is there a way to change group of text color dynamically or must set every text color manually in code?
I searched for how to change theme colors dynamically at run time and i found this answer this answer.
But I also search again and I found this github
but it doesn't work on Android Marshmallow (6.0+) and it's use is discouraged! as he say.
Is there any lib or method to change the theme on runtime?
So far it's impossible and not viable because of themes are immutable.
GreenMatter becomes outdated so regretfully the answer of your question is No way.
More precisely, the color overriding at runtime is not working. There is no fix found at the moment. The future of this feature is uncertain.

Is it possible to insert/paste image on a custom EditText?

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.

How to display Custom font on the onScreenKeyboardof the android device?

I want to change the onscreen keyboard according to the font .ttf file in my assets folder. I searched a lot but it always change the text which we typed but thier is no way i found to change the display of the onScreen Keyboard.
Please any body knows how to do that?
Thanks in advance.
check my answer in this below link. This method will change the font style of your android application and as the keyboard is also in an android application of service so the font of the keyboard is also changed.
This answer is verified and i have used this trick even i was searching of the same from a long time

Change font in all app or at least in Tab

Ok my first question is:
Is there a way to change the font on everything in my app? I mean to put for ex the font x.ttf to be the default font for all the buttons,listviews,for everything that is in my app? And if yes,how?
And my second question:
If that is not possible,then please tell me how to change the font on the Tab widget...
Thanks
Still There is no way to change the font for a complete application. All You can do is for Text Views create custom Text View and override the font method. Then you can use the customized text view rather than using the default text view.
This is the way I used the font Helvetica for My app.

How to return to default style on EditText if I apply a background?

I just encountered with a problem that I don't know how to solve. It looks silly but I cannot find a way to fix it.
I have a form in android with several EditText and when you submit the form it checks those EditText and if they have wrong data I change the EditText to red border (applying a ninepatch image).
myEditText.setBackgroundResource(R.drawable.edittext_red);
The problem is, I want to restore android's default style when the user change the EditText, but I don't know how to do it. if I do:
myEditText.setBackgroundResource(0);
It will just remove everything and that's not what I want.
Thanks!
First, before you call setBackgroundResource with your own ninepatch, store the original background of the EditText, like this:
Drawable originalDrawable = myEditText.getBackground();
Then, if the user entered the wrong data, you can set your red border ninepatch:
myEditText.setBackgroundResource(R.drawable.edittext_red);
And later, when you want to restore the look of the EditText, use the stored drawable:
myEditText.setBackgroundDrawable(originalDrawable);
Alternatively you can reference the default Android EditText background directly like this:
myEditText.setBackgroundResource(android.R.drawable.edit_text);
At androiddrawables you can see how the different drawables look for the different versions of Android, and get their resource identifier. This method should work for all drawables, not just EditText
These (and other android resources) can also be found on your own system, in the android-sdk folder in
< path to android-sdk folder>/android-sdk/platforms/android-< API level>/data/res/
For material design with Kotlin:
edit.apply {
setBackgroundResource(androidx.appcompat.R.drawable.abc_edit_text_material)
}

Categories

Resources