android


Cannot set typeface to tab of TabLayout bind with ViewPager in Android


I ma developing an android app. In my app, I am using TabLayout with ViewPager. But I am having a problem with setting typeface to the tab. I need to set it cause I am embedding font in my app. Please see my scenario below.
This is my ViewPagerAdapter
public class ViewPagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> fragmentList = new ArrayList<Fragment>();
private final List<String> titleList = new ArrayList<String>();
public ViewPagerAdapter(FragmentManager fragmentManager)
{
super(fragmentManager);
}
#Override
public Fragment getItem(int position) {
return fragmentList.get(position);
}
#Override
public int getCount() {
return fragmentList.size();
}
public void addFragment(Fragment fragment,String title)
{
fragmentList.add(fragment);
titleList.add(title);
}
#Override
public CharSequence getPageTitle(int position) {
return titleList.get(position);
}
public void clear()
{
fragmentList.removeAll(fragmentList);
titleList.removeAll(titleList);
}
}
This is how I am setting typeface dynamically to tab
private void setUpTabLayout()
{
adapter = new ViewPagerAdapter(fm);
adapter.addFragment(new DestinationsFragment(), config.getLocSpannableString("title 1 in mm anguage").toString());
adapter.addFragment(new CategoriesFragment(),config.getLocSpannableString("title 2 in mm language").toString());
viewPager.setAdapter(adapter);
tabLayout.setupWithViewPager(viewPager);
}
This is getLocSpannableString method in config class
public SpannableString getLocSpannableString(String text)
{
SpannableString spannableString = new SpannableString(text);
Typeface font = getTypeface();
spannableString.setSpan(new CustomTypefaceSpan("", font), 0, spannableString.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
return spannableString;
}
private void getTypeface()
{
return Typeface.createFromAsset(getAssets(),"fonts/tharlon.ttf");
}
This is the result that is not working
As you can see in screenshot. Tab title are not showing cause setting typeface is not working? Please how can I fix my code? Is there a way to set the typeface of tab title that is binding with ViewPager please? Please help me.

Related Links

how to assign animation duration time android 4.0?
Android 4.0 org.apache.http.conn.ConnectTimeoutException: Connect to … timed out
Action Bar --> Action Item background
Android Chat application smiley
Multiple file extension/mimetype intent-filters with one activity
Holo Dark TabWidget style for Holo Light Theme
ListView doesn't refresh after using changeCursor() on its adapter
Android SyncAdapter Callback
External install for those Android versions that support it, but support for those that don't
Image format of the camera (Android)
How Do I Set My View LayoutParams Width Smaller?
Is it good Practice to start service every 15 minute & destroy it after sending location information in android?
How to know which View is being touched
Android ListView BUG?
Android release keystore issue: “Keystore was tampered with, or password was incorrect”
PhoneGap/Android iFrame resizing out of screen to refit contents

Categories

HOME
phantom-dsl
fabricjs
c++11
apache-flink
wakanda
nunit
mjml
angular2-material
requirements
can
edge
soa
jetty
echo
pega
plist
xcodebuild
openbugs
code-generation
shared-libraries
scrolltop
imessage
digital-signature
symfony-console
cfml
pagespeed
easeljs
roundup
game-theory
progress-bar
wcag
user-defined-functions
scrollview
xbox
code-snippets
sendbird
sharding
nested-lists
jwplayer6
video-capture
nohup
opensmpp
levenshtein-distance
apriori
sharp-snmp
avcapturedevice
plan-9
ovf
openal
reportservice2010
rserve
datamaps
posixct
remedy
oozie-coordinator
seq
renaming
testrail
change-tracking
pure-css
simplepie
google-cloud-console
iotivity
expectations
embedding
nullable
blitline
spring-retry
sciruby
roadkill-wiki
ess
ons-api
video-player
uvc
theos
boost-program-options
ssis-data-flow
machine-instruction
tweenlite
mdichild
isqlquery
script#
cnf
database-create
stress
node-redis
mysql-error-1205
w3c-geolocation
pagemethods
interop-domino
flvplayback
ifilter
lemmatization

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App