2016-08-24 53 views
1

在我的标签布局中,我有3个标签。这个标签的标题默认都是大写字母,我想将Bole,Italic和字体大小等样式应用于标签。 我正在使用选项卡布局并将NoActionBar作为样式查看寻呼机。是否可以为标签标题应用样式

+0

是..its可能 – shahid17june

+0

你可以发布,我们可以将这些风格answer.How? –

+0

当然..只是给我几分钟.. – shahid17june

回答

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); 
    } 
} 
+0

如果我们想要应用任何尺寸和风格,我们可以在custom_tab_item.layout中提到。我明白这是正确还是错误? –

+0

是的,你是对的 –

+0

k我会试试这个,让你知道它是工作r不是。 –

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> 
+0

它不是工作风格是应用于标签中的文本而不是标签标题。我想将样式应用于**标题标题**。 –

相关问题