2016-12-27 6 views
-1

Я новичок в андроиде и подготовил демо для swipable вкладок с помощью viewpager и подготовил его успешно. Теперь я хочу изменить цвет текста вкладка, а также выбор, Пожалуйста, помогите мне разобраться, style.xml Как изменить цвет текста вкладок в Android и фон вкладки в android с помощью viewpager

<style name="MyRadioButtonStyle" parent="@android:style/Widget.CompoundButton.RadioButton"> 
     <item name="android:button">@drawable/radio_selected</item> 
    </style> 

    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar"> 
     <!-- 
      Theme customizations available in newer API levels can go in 
      res/values-vXX/styles.xml, while customizations related to 
      backward-compatibility can go here. 
     --> 
     <item name="colorPrimary">@color/orange</item> 
     <item name="colorPrimaryDark">@color/orange</item> 
     <item name="colorAccent">@color/orange</item> 

     <item name="android:actionBarStyle">@style/MyActionBarTheme</item> 
    </style> 
    <style name="MyActionBarTheme" parent="@android:style/Widget.Holo.Light.ActionBar"> 
     <item name="android:background">@color/orange</item> 
     <item name="android:textColor">@color/white</item> 
    </style> 

    <style name="TabSpecialTheme" parent="android:Theme.Holo.Light.DarkActionBar"> 
     <item name="@android:attr/actionBarTabTextStyle">@style/TabStyle</item> 
    </style> 

    <!-- Modify the text color --> 
    <style name="TabStyle" parent="android:Widget.Holo.Light.ActionBar.TabText.Inverse"> 
     <item name="android:textColor">#F70000</item> 
    </style> 


    <!-- Application theme. --> 
    <style name="AppTheme" parent="AppBaseTheme"> 
     <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
    </style> 


</resources> 

main_listing.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.view.ViewPager 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/pager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 

    /> 

mainListing.java

public class MainListingActivity extends FragmentActivity { 
    ViewPager Tab; 
    TabsPagerAdapter TabAdapter; 
    ActionBar actionBar; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_listing); 

     TabAdapter = new TabsPagerAdapter(getSupportFragmentManager()); 

     Tab = (ViewPager)findViewById(R.id.pager); 
     Tab.setOnPageChangeListener(
       new ViewPager.SimpleOnPageChangeListener() { 
        @Override 
        public void onPageSelected(int position) { 

         actionBar = getActionBar(); 
         actionBar.setSelectedNavigationItem(position); 
         actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#F05423"))); 

        } 
       }); 
     Tab.setAdapter(TabAdapter); 

     actionBar = getActionBar(); 
     //Enable Tabs on Action Bar 
     actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 
     ActionBar.TabListener tabListener = new ActionBar.TabListener(){ 

      @Override 
      public void onTabReselected(android.app.ActionBar.Tab tab, 
             FragmentTransaction ft) { 
       // TODO Auto-generated method stub 


      } 

      @Override 
      public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) { 

       Tab.setCurrentItem(tab.getPosition()); 
      } 

      @Override 
      public void onTabUnselected(android.app.ActionBar.Tab tab, 
             FragmentTransaction ft) { 
       // TODO Auto-generated method stub 

      }}; 
     //Add New Tab 
     actionBar.addTab(actionBar.newTab().setText("All").setTabListener(tabListener)); 
     actionBar.addTab(actionBar.newTab().setText("Gents").setTabListener(tabListener)); 
     actionBar.addTab(actionBar.newTab().setText("Ladies").setTabListener(tabListener)); 
     actionBar.addTab(actionBar.newTab().setText("Kids").setTabListener(tabListener)); 


    } 

    //change tab color.. 
    public void setTabColor(TabHost tabhost) { 

     for (int i = 0; i < tabhost.getTabWidget().getChildCount(); i++) 
      tabhost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#ffffff")); //unselected 

     if (tabhost.getCurrentTab() == 0) { 
      tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(Color.parseColor("#F05423")); 
      //1st tab selected 
     } else { 
      tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(Color.parseColor("#F05423")); 
     } 
    } 

} 

ответ

0
<style name="TabSpecialTheme" parent="android:Theme.Holo.Light.DarkActionBar"> 
    <item name="@android:attr/actionBarTabTextStyle">@style/TabStyle</item> 
</style> 

<!-- Modify the text color --> 
<style name="TabStyle" parent="android:Widget.Holo.Light.ActionBar.TabText.Inverse"> 
    <item name="android:textColor">#F70000</item> 
</style>> 
+0

hy..ku6 BHI изменение Най хуа .. :( –

+0

вы дзе tumne метод ниши bnya хаи установить закладку цвет Isme цвет установить kiye час уже –

+0

мене стиль bhi добавить kri для лучшего понимания –

Смежные вопросы