Set proper font of all TextViews on ToolBar
Calligraphy currently doesn't support setting of font through styles for
ToolBar due to which this hack is necessary.
Link to the relevant issue on the Calligraphy's GitHub page:
@@ -39,6 +39,8 @@ import java.util.ArrayList;
import java.util.List;
import de.greenrobot.event.EventBus;
+import uk.co.chrisjenx.calligraphy.CalligraphyUtils;
+import uk.co.chrisjenx.calligraphy.TypefaceUtils;
public abstract class BaseFragmentActivity extends BaseAppActivity
implements NetworkSubject, ICommonUI, OnActivityResultListener {
@@ -90,6 +92,23 @@ public abstract class BaseFragmentActivity extends BaseAppActivity
if (toolbar != null && toolbar instanceof Toolbar) {
setSupportActionBar((Toolbar) toolbar);
configureActionBar();
+ setToolBarFont();
+ }
+ }
+
+ /**
+ * Sets the font of any TextView found within the ToolBar.
+ * <br/>
+ * TODO: Remove this function when this issue gets resolved: https://github.com/chrisjenx/Calligraphy/issues/295
+ */
+ private void setToolBarFont() {
+ final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
+ for (int i = 0; i < toolbar.getChildCount(); i++) {
+ final View child = toolbar.getChildAt(i);
+ if (child instanceof TextView) {
+ final TextView textView = (TextView) child;
+ CalligraphyUtils.applyFontToTextView(textView, TypefaceUtils.load(getAssets(), "fonts/OpenSans-Semibold.ttf"));
+ }
}
}
@@ -516,7 +535,7 @@ public abstract class BaseFragmentActivity extends BaseAppActivity
/**
* {@inheritDoc}
- *
+ * <p>
* <p>To conform with the {@link OnActivityResultListener} interface this function has been
* implemented emptily, making it publicly accessible.</p>
*/
