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 make shape of FAB button to be like triangle
ScrollTo does not work when NestedScrollView has focus
How to call a Progress Dialog in Fragment?
Write file in android with angular and ngCordova
is It possible to develop common business logic that run in both android and iOS platform?
How do I remove an app drawer button without removing an app drawer?
Android SplitScreen orientation
onDataChange is getting called twice in android Firebase
using .so library in android studio
git push -u origin master remote: Permission to user android studio
Android ImageView creates unneeded padding inside
calabash-android: wait for string with id to appear
Checkbox not displaying in custom row
AutoCompleteTextView not working in Huawei devices
TextView fade out and disappear
how to open the password protect pdf through Authenticatoin

Categories

HOME
cygwin
kentico
amp-html
numbers
interface
jelastic
composite-primary-key
jsf-2.2
graphics
carousel
switch-statement
regular-language
settings
jtextpane
little-proxy
appcelerator-studio
line
google-form
altera
jersey-1.0
identity-management
googlebot
poedit
kendo-mobile
imagemap
dpdk
google-cloud-print
fable-f#
gitlab-api
database-comparison
glib
hreflang
engine.io
python-pptx
alphabetical
ideascript
filesystemwatcher
diacritics
spring-mvc-test
comparison-operators
microsoft-metro
manova
subnet
spring-data-couchbase
bbpress
rxtx
restore
rocks
cubism.js
ziparchive
mongodb-php
model-associations
pypiserver
flock
.bash-profile
canalyzer
eoferror
viola-jones
linked-tables
ms-access-2000
git-ftp
user-permissions
mass-assignment
delayed-execution
pseudo-class
create.js
kissfft
verold
jjaql
ray
dsym
drupal-nodes
getopt
time.h
node-blade
android-icons
web-notifications
android-loadermanager
pstack
sentestingkit
convention
android-holo-everywhere
quotation-marks
photolibrary
maven-1
message-passing
pagemethods
murmurhash
interop-domino
fail-fast-fail-early
application-planning

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