2016-08-24 9 views
1

私のタブレイアウトには3つのタブがあります。このタブのタイトルはすべて大文字です。Bole、Italic、およびフォントサイズなどのスタイルを別々にタブに適用したいと考えています。 NoActionBarをスタイルとしてタブレイアウトとビューページャーを使用しています。タブタイトルにスタイルを適用することは可能ですか

+0

はい – shahid17june

+0

あなたは私たちがこれらのスタイルを適用することができますanswer.Howを投稿することができます可能..its? –

+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

android.support.design.widget.TabLayout内部210
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

私はこれを試して、あなたがそれが仕事ではないことを知らせます。 –

0

この

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

タブのタイトルではなくタブのテキストに作業スタイルが適用されていません。**タブのタイトル**にスタイルを適用します。 –

関連する問題