如何自定义标签片段上的 ttf 字体?我正在使用sherlockactionbar。这是我的代码,
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
<FrameLayout
android:id="@+id/ptr_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
在主要活动中使用,
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/** to check whether user logged in or not */
session = new TwitterHomeActivity(getApplicationContext());
session.checklogin();
/** Getting a reference to action bar of this activity */
mActionBar = getSupportActionBar();
getSupportActionBar().setDisplayUseLogoEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mActionBar.setDisplayOptions(0, ActionBar.DISPLAY_USE_LOGO);
/** Set tab navigation mode */
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
/** Getting a reference to ViewPager from the layout */
mPager = (ViewPager) findViewById(R.id.pager);
/** Getting a reference to FragmentManager */
FragmentManager fm = getSupportFragmentManager();
/** Defining a listener for pageChange */
ViewPager.SimpleOnPageChangeListener pageChangeListener = new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
super.onPageSelected(position);
setTitle(getTitleFromPosition(position));
mActionBar.setSelectedNavigationItem(position);
// mActionBar.setBackgroundDrawable(R.drawable.ic_action_chance_icon);
}
private CharSequence getTitleFromPosition(int position) {
if (position == 0) {
title = "text";
} else if (position == 1) {
title = "text";
} else if (position == 2) {
title = "text";
} else if (position == 3) {
title = "text";
}
return title;
}
};
/** Setting the pageChange listner to the viewPager */
mPager.setOnPageChangeListener(pageChangeListener);
/** Creating an instance of FragmentPagerAdapter */
MyFragmentPagerAdapter fragmentPagerAdapter = new MyFragmentPagerAdapter(
fm);
/** Setting the FragmentPagerAdapter object to the viewPager object */
mPager.setAdapter(fragmentPagerAdapter);
mActionBar.setDisplayShowTitleEnabled(true);
/** Defining tab listener */
ActionBar.TabListener tabListener = new ActionBar.TabListener() {
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
mPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
};
/**/
Tab tab = mActionBar.newTab();
tab = mActionBar.newTab();
tab.setText(“text”);
tab.setTabListener(tabListener);
mActionBar.addTab(tab);
tab = mActionBar.newTab();
tab.setText(“ttext”);
tab.setTabListener(tabListener);
mActionBar.addTab(tab);
tab = mActionBar.newTab();
tab.setText(“text”);
tab.setTabListener(tabListener);
mActionBar.addTab(tab);
tab = mActionBar.newTab();
tab.setText(“text”);
tab.setTabListener(tabListener);
mActionBar.addTab(tab);
try {
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class
.getDeclaredField("sHasPermanentMenuKey");
if (menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
} catch (Exception ex) {
// Ignore
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.camera:
startActivity(new Intent(MainActivity.this, Request_Broadcast.class));
overridePendingTransition(R.anim.right_slide_in,
R.anim.right_slide_out);
return true;
case R.id.find_people:
startActivity(new Intent(MainActivity.this, Find_people.class));
overridePendingTransition(R.anim.right_slide_in,
R.anim.right_slide_out);
return true;
case R.id.action_settings:
startActivity(new Intent(MainActivity.this, Pro_settings.class));
overridePendingTransition(R.anim.right_slide_in,
R.anim.right_slide_out);
return true;
}
return true;
}
@SuppressLint("NewApi")
public void setActionBarTitle(int feedPage) {
getActionBar().setTitle(feedPage);
}
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void onPageSelected(int arg0) {
}
}
现在我想使用字体自定义选项卡上的字体。如何做到这一点,选项卡上的文本以大写字母显示。我想用小写字母显示..