
When we use different font in our Android app, it is necessary to use the same font throughout the application. So you have to change the font in the toolbar(action bar).
For that you have to create TextView and set the TypeFace(font) of your choice to that TextView and set it to the action bar as custom view. Checkout the below code for the same.
TextView tv = new TextView(getApplicationContext()); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT); tv.setLayoutParams(lp); tv.setText("Welcome!); tv.setTextSize(20); tv.setTextColor(Color.parseColor("#FFFFFF")); Typeface tf = Typeface.createFromAsset(getAssets(), "Asap-Medium.otf"); tv.setTypeface(tf); getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); getSupportActionBar().setCustomView(tv);
vielen dank freunde
How to center the text in Action bar?
Hello Shahu!
You can use “addRule” to achieve this in above code. i.e. “lp.addRule(RelativeLayout.CENTER_HORIZONTAL);”
Here you can use CENTER_HORIZONTAL or just CENTER
Hello Shahu!
You can use “addRule” to achieve this in above code. i.e. “lp.addRule(RelativeLayout.CENTER_HORIZONTAL);”
Here you can use CENTER_HORIZONTAL or just CENTER