2015-09-01 2 views
0

Я не уверен, что это возможно. Я пытаюсь сделать экран с вкладками и списками на каждой вкладке (я уже сделал это), и я сделал пользовательский ActionBar для названия и некоторых значков на нем, теперь я хочу изменить цвет текста язычки, я решил цвет фона, но я не могу найти ничего, связанные с цветом текста, здесь кусок моего кода .java и мой manifest.xmlКак настроить вкладки Android без изменения actionBar? (с помощью ViewPager)

addMenu(); 

     // Set up the action bar. 
     final ActionBar actionBar = getSupportActionBar(); 
     actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 
     actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#ffffff"))); 
     actionBar.show(); 

     actionBar.setDisplayOptions(actionBar.getDisplayOptions() | ActionBar.DISPLAY_SHOW_CUSTOM); 


     // Create the adapter that will return a fragment for each of the three 
     // primary sections of the activity. 

     mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); 


     // Set up the ViewPager with the sections adapter. 
     mViewPager = (ViewPager) findViewById(R.id.pager); 
     mViewPager.setAdapter(mSectionsPagerAdapter); 

     // When swiping between different sections, select the corresponding 
     // tab. We can also use ActionBar.Tab#select() to do this if we have 
     // a reference to the Tab. 
     mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { 
      @Override 
      public void onPageSelected(int position) { 
       actionBar.setSelectedNavigationItem(position); 
      } 
     }); 

     // For each of the sections in the app, add a tab to the action bar. 
     for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { 
      // Create a tab with text corresponding to the page title defined by 
      // the adapter. Also specify this Activity object, which implements 
      // the TabListener interface, as the callback (listener) for when 
      // this tab is selected. 
      actionBar.addTab(
        actionBar.newTab() 
          .setText(mSectionsPagerAdapter.getPageTitle(i)) 
          .setTabListener(this) 
          ); 

     } 

метод addMenu (только изменения Бар Action):

getSupportActionBar().setDisplayOptions(android.support.v7.app.ActionBar.DISPLAY_SHOW_CUSTOM); 
    LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE); 
    View view = inflater.inflate(R.layout.order_title, null); 
    TextView textView = (TextView) view.findViewById(R.id.mytext); 
    textView.setWidth(getWindow().getWindowManager().getDefaultDisplay().getWidth()); 
    textView.setPadding(0, 0, 50, 0); 
    textView.setGravity(Gravity.CENTER); 

    Typeface segoeui = Typeface.createFromAsset(getAssets(),"fonts/segoeui.ttf"); 
    textView.setTypeface(segoeui); 
    textView.setText("Some Text"); 
    getSupportActionBar().setCustomView(view); 
    getSupportActionBar().setHomeAsUpIndicator(R.drawable.arrow_left); 
    getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
    getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#afafaf"))); 

и мой manifest.xml:

<activity 
     android:name=".Activity1" 
     android:label="@string/title_activity1" 
     android:parentActivityName=".MainActivity" 
     android:screenOrientation="portrait" 
     > 
     <meta-data 
      android:name="android.support.PARENT_ACTIVITY" 
      android:value="cleanpress.cleanpress.MainActivity" /> 
    </activity> 

Вот как это выглядит: http://i.stack.imgur.com/0hRbv.png

Как вы можете видеть на экране, что я работаю связан с другой (если это уместно). Я хочу изменить только цвет текста вкладок (есть 3 вкладки), кто-нибудь может мне помочь?

(я уже работал с форматом HTML и не работал)

ответ

1

Вы должны использовать android.support.design.widget.TabLayout для обработки вкладок , так что вы можете настроить:

app:tabIndicatorColor="@color/colorAccent" //indicator color 
    app:tabSelectedTextColor="#EEE" // text color on selected tab 
    app:tabTextColor="#EEE" // text color on tab 

вы также должны использовать android.support.v7.widget.Toolbar для ActionBar.

Exmaple:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    tools:context=".MainActivity" 
    android:id="@+id/root" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

      <android.support.v7.widget.Toolbar 
       android:layout_alignParentTop="true" 
       android:text="@string/app_name" 
       android:id="@+id/app_bar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:background="@color/colorPrimary" 
       android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/> 

      <android.support.design.widget.TabLayout 
       android:id="@+id/tab_layout" 
       android:layout_below="@+id/app_bar" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@color/colorPrimary" 
       app:tabIndicatorColor="@color/colorAccent" 
       app:tabSelectedTextColor="#EEE" 
       app:tabTextColor="#EEE" /> 


    <android.support.v4.view.ViewPager 
     android:id="@+id/view_pager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@id/tab_layout" /> 

</RelativeLayout> 

В деятельности в OnCreate

 Toolbar toolbar = (Toolbar) findViewById(R.id.app_bar); 
     setSupportActionBar(toolbar); 
     mAdapter = new YourPagerAdapter(getSupportFragmentManager()); 
     mPager.setAdapter(mAdapter); 
     mTabLayout.setupWithViewPager(mPager); 

Не забудьте добавить

compile 'com.android.support:appcompat-v7:23.0.0' 
compile 'com.android.support:design:23.0.0' 
compile 'com.android.support:support-v4:23.0.0' 

в Gradle зависимостей

0

попробовать это в стилях

 <style name="MyTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar"> 
<item name="android:actionBarTabTextStyle">@style/Widget.MyTabText</item> 
</style> 

<style name="Widget.MyTabText" parent="@style/Widget.AppCompat.ActionBar.TabText"> 
     <item name="android:textColor">@color/#your_color</item> 
</style> 
+0

это действительно работало, но фон был тем, кто изменил не текст .. есть ли способ отредактировать это? –

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