在我的标签布局中,我有3个标签。这个标签的标题是默认全部在大写字母我想要以不同的方式应用标签,例如Bole,Italic和字体大小。 我使用标签布局和查看寻呼机与NoActionBar作为样式。
答案 0 :(得分:1)
无法将样式应用于默认的标签标题。以下链接将帮助您创建自定义标签。
http://mrbool.com/how-to-customize-tab-layout-in-android/28153
答案 1 :(得分:0)
是的,你可以,按照这个
custom_tab_item
:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tab"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="@dimen/tab_label"/>
main_layout
:
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_scrollFlags="scroll|enterAlways">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textStyle="bold"
style="@android:style/TextAppearance.Medium"
android:text="Toolbar Title" />
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
app:tabGravity="fill"
app:tabIndicatorColor="@android:color/white"
app:tabMode="fixed" />
Activity
:
public class DiningActivity extends AppCompatActivity {
private Toolbar mToolbar;
private TabLayout mTabLayout;
private ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dining);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
((TextView) findViewById(R.id.toolbar_title)).setText(R.string.dining);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mViewPager = (ViewPager) findViewById(R.id.viewpager);
setupViewPager(mViewPager);
mTabLayout = (TabLayout) findViewById(R.id.tabs);
mTabLayout.setupWithViewPager(mViewPager);
setupTabs();
}
private void setupViewPager(ViewPager viewPager) {
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.addFragment(new RestaurantFragment(), getString(R.string.restaurants));
adapter.addFragment(new HotelsFragment(), getString(R.string.hotels));
adapter.addFragment(new BarsPubsFragment(), getString(R.string.bars_pubs));
viewPager.setAdapter(adapter);
}
private void setupTabs() {
TextView tabOne = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab_item, null);
tabOne.setText(getString(R.string.restaurants));
mTabLayout.getTabAt(0).setCustomView(tabOne);
TextView tabTwo = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab_item, null);
tabTwo.setText(getString(R.string.hotels));
mTabLayout.getTabAt(1).setCustomView(tabTwo);
TextView tabThree = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab_item, null);
tabThree.setText(getString(R.string.bars_pubs));
mTabLayout.getTabAt(Numerics.TWO).setCustomView(tabThree);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
super.onBackPressed();
}
return super.onOptionsItemSelected(item);
}
}
答案 2 :(得分:0)
在android.support.design.widget.TabLayout里面设置像这样的主题属性
android:theme="@style/Base.Widget.Design.TabLayout"
并定义样式主题
<style name="Base.Widget.Design.TabLayout" parent="android:Widget">
<item name="android:fontFamily">sans-serif</item>
<item name="android:textStyle">normal</item>
</style>