0

탭 뷰어의 색상을 변경하려고하지만 모든 것을 시도했지만 색상을 변경하지 않았습니다. 이 내가 탭을 사용자 정의 할 노력하고있어 활동은 다음과 같습니다 LocationsActivity.java :ViewPager v4의 백그라운드 탭 변경

import android.content.Intent; 
import android.os.Bundle; 
import android.support.v4.app.FragmentManager; 
import android.support.v4.app.FragmentTransaction; 
import android.support.v4.view.ViewPager; 
import android.support.v7.app.ActionBar; 
import android.support.v7.app.ActionBar.Tab; 
import android.support.v7.app.ActionBarActivity; 
import android.view.Menu; 
import android.view.MenuItem; 

import com.jad.pholoc.util.LocationsFragmentPagerAdapter; 


public class LocationsActivity extends ActionBarActivity { 

    private ViewPager mPager; 
    public static FragmentManager fragmentManager; 
    private LocationsFragmentPagerAdapter fragmentPagerAdapter; 
    private ActionBar mActionbar; 

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

     mActionbar = getSupportActionBar(); 

     mActionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 

     mPager = (ViewPager) findViewById(R.id.pager); 

     fragmentManager = getSupportFragmentManager(); 

     ViewPager.SimpleOnPageChangeListener pageChangeListener = new ViewPager.SimpleOnPageChangeListener() { 
      @Override 
      public void onPageSelected(int position) { 
       super.onPageSelected(position); 
       mActionbar.setSelectedNavigationItem(position); 
      } 
     }; 

     mPager.setOnPageChangeListener(pageChangeListener); 


     fragmentPagerAdapter = new LocationsFragmentPagerAdapter(
       fragmentManager); 

     mPager.setAdapter(fragmentPagerAdapter); 

     mActionbar.setDisplayShowTitleEnabled(true); 

     ActionBar.TabListener tabListener = new ActionBar.TabListener() { 

      @Override 
      public void onTabUnselected(Tab tab, FragmentTransaction ft) { 
      } 

      @Override 
      public void onTabSelected(Tab tab, FragmentTransaction ft) { 
       mPager.setCurrentItem(tab.getPosition()); 
      } 

      @Override 
      public void onTabReselected(Tab tab, FragmentTransaction ft) { 
      } 
     }; 

     Tab tab = mActionbar.newTab().setText("Lista") 
       .setTabListener(tabListener); 

     mActionbar.addTab(tab); 

     tab = mActionbar.newTab().setText("Mapa").setTabListener(tabListener); 

     mActionbar.addTab(tab); 

    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.locations, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 
     if (id == R.id.acercade) { 
      Intent i = new Intent(this, AcercaDeActivity.class); 
      startActivity(i); 
      return true; 
     } 
     return super.onOptionsItemSelected(item); 
    } 

} 

activity_locations.xml :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <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" > 
    </android.support.v4.view.ViewPager> 

</RelativeLayout> 

styles.xml :

<resources> 
    <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light"> 
     <item name="actionBarStyle">@style/ActionBarStyle</item> 
     <item name="actionBarTabStyle">@style/ActionBarTabStyle.Example</item> 
    </style> 

    <style name="ActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"> 
     <item name="titleTextStyle">@style/TitleBarTextColor</item> 
     <item name="background">@color/blue_pholoc</item> 
     <item name="android:backgroundStacked">@color/blue_pholoc</item> 
    </style> 

    <style name="TitleBarTextColor" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"> 
     <item name="android:textColor">@color/white</item> 
    </style> 

    <style name="ActionBarTabStyle.Example" parent="@style/Widget.AppCompat.Light.ActionBar.TabView"> 
     <item name="android:background">@drawable/tab_indicator_ab_example</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> 

현재의 모습 이 액티비티 (이미지) :

https://dl.dropboxusercontent.com/u/30731371/LocationsActivity.png

내가 말했듯이, 나는 탭의 색깔을 바꾸고 싶지만 불가능하다. 그냥 회색으로 보인다.

PD : 저는 스페인어로 영어로 글을 쓰지 않습니다 (Google 번역).

+0

을 감소, 나는의 색상을 변경 선택된 탭을 나타내는 탭 아래의 선은 표시되지 않습니다. –

+0

ActionBarStyle 스타일에서 android : backgroundStacked를 backgroundStacked로 변경하는 탭의 색상을 변경했습니다. 이제 탭 아래의 선 색상을 흰색으로 변경하고 싶지만 바꿀 수는 없습니다. –

답변

1

이 라이브러리 사용을 고려해 보셨습니까? https://github.com/astuetz/PagerSlidingTabStrip?

그럼 당신은 당신의 레이아웃이 같은 색상을 설정할 수 있습니다

android:background="@color/memrise_blue" 

훨씬 쉽게

, 또한 코드 : 나는 부분적으로 문제를 해결 한

+0

문제는 어떤 이유로 든 스타일이 탭에 적용되지 않고 해결하고자하는 것입니다. –

관련 문제