tablayout标题的字体

大家好我正在一个标签的应用程序..我如何设置自定义字体为android中的tablayout标题?我想使用自定义字体的标题,我试过搜索,但没有找到任何方式tablayout标题的字体

我的代码谢谢你的帮助.....!

MainActivity.java

public class MainActivity extends AppCompatActivity { 

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

setSupportActionBar(toolbar);

TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);

tabLayout.addTab(tabLayout.newTab().setText("ONE"));

tabLayout.addTab(tabLayout.newTab().setText("TWO"));

tabLayout.addTab(tabLayout.newTab().setText("OTHER"));

tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);

final PagerAdapter adapter = new PagerAdapter

(getSupportFragmentManager(), tabLayout.getTabCount());

viewPager.setAdapter(adapter);

viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));

tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {

@Override

public void onTabSelected(TabLayout.Tab tab) {

viewPager.setCurrentItem(tab.getPosition());

}

@Override

public void onTabUnselected(TabLayout.Tab tab) {

}

@Override

public void onTabReselected(TabLayout.Tab tab) {

}

});

}

回答:

在布局

<android.support.design.widget.TabLayout 

android:id="@+id/sliding_tabs"

style="@style/Tab"

android:layout_width="match_parent"

android:layout_height="54dp"

app:tabTextAppearance="@style/MineCustomTabText"/>

和你的风格的文件夹

<style name="MineCustomTabText" parent="TextAppearance.Design.Tab"> 

<item name="android:textSize">12sp</item>

<item name="android:textAllCaps">true</item>

<item name="android:fontFamily">@font/two_light_1</item>

</style>

以上是 tablayout标题的字体 的全部内容, 来源链接: utcz.com/qa/264989.html

回到顶部