android Settings: adjust font size - android

In the settings in my phone can I change the font size of apps globally .
Settings> Display> Font size
Can I make the font size (small, normal, large , very large ) also read with Java and, if applicable . set only for my app ?
I tried to change the font size as follows.
Button buttonbig = (Button) dialog.findViewById(R.id.btn_big);
buttonbig.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
float fScale = getResources().getConfiguration().fontScale;
String fontSize = String.valueOf(fScale);
conf.fontScale =fScale + 0.15f;
getResources().getConfiguration().setTo(conf);
TextView textView = (TextView) dialog.findViewById(R.id.lbl_size_act);
textView.setText(fontSize);
}
});
dialog.show();
My Text View shows me the new size . However, the text remains the same size .Have anyone an idea what's wrong ?

First of all, I strongly advise against overriding the language, font size, or other settings, because as you pointed out, this is something you should do globally.
If you want to set it for your whole app, the right place to do so would be in the Application.
public class App extends Application {
#Override
public void onCreate() {
super.onCreate();
Configuration configuration = getResources().getConfiguration();
configuration.fontScale *= 2;
getResources().updateConfiguration(configuration, getResources().getDisplayMetrics());
}
}
If you want to change it during runtime, you would also set it in application, but you would have to finish and start your activity again to take effect.

If you want to change only this textView's font size, how about trying
textView.setTextSize(float);
http://developer.android.com/reference/android/widget/TextView.html#setTextSize(float)

Related

How to change font family or size for the text on ConfirmationOvelay

I want to change font family and text size on ConfirmationOverlay
Any idea? Does it change with system font?
// Defaults to SUCCESS_ANIMATION
new ConfirmationOverlay().showOn(myActivity);
new ConfirmationOverlay()
.setType(ConfirmationOverlay.OPEN_ON_PHONE_ANIMATION)
.setDuration(3000)
.setMessage("Opening...")
.setOnAnimationFinishedListener(new ConfirmationOverlay.OnAnimationFinishedListener() {
#Override
public void onAnimationFinished() {
// Finished animating and the content view has been removed from myActivity.
}
}).showOn(myActivity);
// Default duration is DEFAULT_ANIMATION_DURATION_MS
new ConfirmationOverlay()
.setType(ConfirmationOverlay.FAILURE_ANIMATION)
.setMessage("Failed")
.setOnAnimationFinishedListener(new ConfirmationOverlay.OnAnimationFinishedListener() {
#Override
public void onAnimationFinished() {
// Finished animating and the view has been removed from myView.getRootView().
}
}).showAbove(myView);
You can't change the ConfirmationOverlay font and text size.
You could, however, create your own custom dialog.
See an example here

How do you open the font size settings directly from an intent?

I would like the user to be able to edit the font size and font style from within my app. The app should just call the default settings.
example:
displayBtn = (Button) findViewById(R.id.displayBtn);
displayBtn .setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(Settings.ACTION_DISPLAY_SETTINGS));
}
});
XML is not editable in run time so you can are going to have to set a static value for the font size and then manually set them in the applicaiton.
For example..
public static int defaultFontSize = defaultValue;
//Update the value when the user changes font..
ClassName (class where you declared the static variable).defaultFontSize = 10;
textView.setTextSize(ClassName.defaultFontSize);

Change Text in a same Layout

I'm Making simple app for project
That App contains lot of text so i want,
"when a button is pressed, text should Change in same layout"
like PowerPoint slide.
I want change text only not scroll.
Now i made my app, have lots of Windows or Layouts.
It is not looking good, too much layout in simple app so please help me .
Thanks in advance
Doing this is very easy, I will quickly walk you through the Algorithm:
Set a class level variable called as FLAG initialize it to 1.
Let us assume that FLAG = 1 will represent the first slide. FLAG = 2 the second slide and so on.
Now in your button click you can use a switch case or an if else condition, based on the value of the flag display the relevant text in textview.
Once done, increment the flag, for the next set of sentence(s).
Class level:
int FLAG = 1;
onCreate:
Initialize your textView:
TextView mtv = (TextView)findViewById(R.id.yourid);
Set a button click listener:
private View.OnClickListener slides = new View.OnClickListener() {
#Override
public void onClick(View v) {
if(FLAG ==1)
mtv.setText("First slide");
else if(FLAG ==2)
mtv.setText("Second Slide");
//and so on...
FLAG = FLAG+1;//increment flag
}
};

CardsUI library setTextSize by clicking on an actionbar button

I am usin the CardsUI library taken from here: http://www.androidviews.net/2012/12/cardsui/
and trying to change the textview size for all the cards by pressing a button.
At the moment i haven't used any buttons, just wanted to check if my approach is correct by setting a fixed textsize.
I have created:
MainActivity.java
MyCard androidViewsCard = new MyCard("Title","Description");
androidViewsCard.setSize(20.0f);
MyCard.java
public void setSize(float f) {
View view = LayoutInflater.from(MainActivity.getAppContext()).inflate(R.layout.card_layout, null);
TextView tv = (TextView) view.findViewById(R.id.description);
tv.setTextSize(f);
}
The text does not change size though. Am i missing something?
Just add a unit with it.
You need to use the function setTextSize(unit, size) with unit SP like this,
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, f);//tv is textView

Application label font not preserved on orientation change

I am not able to preserve the font for my application label on screen orientation change. Currently I am setting the font using the below code in the onCreate method of SherlockFragmentActivity.
titleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
if(titleId == 0)
titleId = com.actionbarsherlock.R.id.abs__action_bar_title;
mAppName = (TextView) findViewById(titleId);
Typeface face = Typeface.createFromAsset(getAssets(), "fonts/handsean.ttf");
mAppName.setTypeface(face);
On Orientation change the font reverts back to the default. I tried preserving state using manifest.xml but it didnot help. it preserves everything except the label font. Can someone suggest how this can be done ?
Thanks for stopping by and reading this post.
Did you tried setting android:configChanges="orientation" and handling the orientation change with onConfigurationChanged()?
edit: also explained here why it's not functioning.
**Yes we can do this.
Override onConfigurationChanged
set the action bar title inside a handler with a delay of 200.**
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
//your code to set the action bar title
setActionBarTitle(title);
}
}, 200);
}

Categories

Resources