8

के साथ काम नहीं कर रहा है मैंने देखा कि ViewPagerIndicator के नवीनतम संस्करण के साथ, आईसीएस स्टाइल डिवाइडर समर्थित हैं, मैंने समस्या और समाधान का पालन करने का प्रयास किया, लेकिन इससे कोई फर्क नहीं पड़ता कि मैं क्या कर रहा हूं TitlePageIndicator के लिए एक्शनबार पर मेरे विकल्पों पर दिखाएं। मैंने IcsLayout को कंटेनर के रूप में जोड़ा, विभाजक, शो डिवाइडर और अन्य गुणों को रखा, लेकिन अभी भी कुछ भी नहीं मिल रहा है। यहाँ मेरी लेआउट (अजीब तरह से पर्याप्त है, अगर मैं ऐप्लिकेशन क्रैश viewpager सूचक एक, के लिए IcsLayout स्विच) है:डिवाइडर TitlePageIndicator के लिए viewpagerindicator और actionbarsherlock

<com.actionbarsherlock.internal.widget.IcsLinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res/com.sosick.android.brink" 
    android:layout_width="match_parent" 
    android:divider="#ffffff" 
    android:showDividers="middle" 
    android:dividerPadding="8dp" 
    android:dividerHeight="10dp" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <com.viewpagerindicator.TitlePageIndicator 
     android:id="@+id/tpi_header" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     textColor="@color/text_light" 
     android:background="@drawable/ab_stacked_solid_brink" 
     app:topPadding="10dp" 
     app:footerPadding="15dp" 
     app:footerColor="#a4ded7" 
     app:footerIndicatorHeight="2dp" 
     app:footerIndicatorStyle="underline" 
     app:footerLineHeight="2dp" 
     app:selectedBold="false" /> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/vp_pages" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" /> 

</com.actionbarsherlock.internal.widget.IcsLinearLayout> 
+0

पेज यह वे कहते हैं कि यह TabPageIndicator साथ काम करता है लगता है पढ़ना है, तो मैं मुझे यकीन नहीं है कि यह शीर्षक इंडिकेटर के साथ संभव है ...? – dariusriggins

+0

आप जो हासिल करना चाहते हैं उसे बेहतर तरीके से समझने के लिए कृपया एक स्केच या संदर्भ पोस्ट करें। धन्यवाद। –

+0

यदि आप इस ऐप को देखते हैं, तो शीर्षक पेजर पर लंबवत डिवाइडर देखें, यही वह है जिसे मैं प्राप्त करने की कोशिश कर रहा हूं। http://24.media.tumblr.com/8044b5ed0a7f8ad04468def5973275d7/tumblr_mi5ru5f7fZ1r2wjwko1_1280.png – dariusriggins

उत्तर

4

आपको लेआउट xml की बजाय शैली में विभाजक पैराम घोषित करने की आवश्यकता है।

../res/values/styles.xml:

<style name="StyledIndicators" parent="@android:style/Theme.Light"> 
    <item name="vpiIconPageIndicatorStyle">@style/CustomIconIndicator</item> 
</style> 

<style name="CustomIconIndicator" parent="Widget.TabPageIndicator"> 
    <item name="android:divider">@drawable/custom_tab_indicator_divider</item> 
    <item name="android:showDividers">middle</item> 
    <item name="android:dividerPadding">10dp</item> 
</style> 

अपनी गतिविधि के लिए प्रकट में:

<activity 
     android:name=".SampleIconsDefault" 
     android:label="Icons/Default" 
     android:theme="@style/StyledIndicators"> 
</activity> 
+0

इस समाधान के लिए एपीआई स्तर 11 की आवश्यकता है, क्या कोई और तरीका है जो एपीआई स्तर 8 के लिए भी काम करता है? –

0

के बाद कोड के टुकड़े mainlyfrom हैं Android Developer साइट। एक बहुत अच्छा उदाहरण ऐप/प्रोजेक्ट भी है।

अपने लेआउट के लिए कंटेनर के रूप में ViewPage का उपयोग करें, उदा। रेस/लेआउट/activity_main.xml:

<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" /> 

एबीएस लागू 'अपनी कक्षा में ActionBar.TabListener, जोड़ सकते हैं और समर्थन पुस्तकालय उदा .:

public class TheDesertFoxActivity extends SherlockFragmentActivity 
     implements ActionBar.TabListener { 

    private AppSectionsPagerAdapter mAppSectionsPagerAdapter; 
    private ViewPager mViewPager; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager()); 

     // Set up action bar 
     final ActionBar actionBar = getSupportActionBar(); 
     actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 

     // Set up the ViewPager, attaching the adapter 
     mViewPager = (ViewPager) findViewById(R.id.pager); 
     mViewPager.setAdapter(mAppSectionsPagerAdapter); 
     mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { 
      @Override 
      public void onPageSelected(int position) { 
       // When swiping between different app sections, select the corresponding tab 
       actionBar.setSelectedNavigationItem(position); 
      } 
     }); 

     // For each of the sections in the app, add a tab to the action bar 
     for (int i = 0; i < mAppSectionsPagerAdapter.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 
      // listener for when this tab is selected. 
      actionBar.addTab(actionBar.newTab() 
        .setText(mAppSectionsPagerAdapter.getPageTitle(i)) 
        .setTabListener(this)); 
     } 
    } 

    public static class AppSectionsPagerAdapter extends FragmentPagerAdapter { 

     public AppSectionsPagerAdapter(FragmentManager fm) { 
      super(fm); 
     } 

     @Override 
     public Fragment getItem(int i) { 
      switch (i) { 

       Fragment fragment = new MyTabsFragment(); 
       Bundle args = new Bundle(); 
       args.putInt(MyTabsFragment.TAB_ID, i); 
       fragment.setArguments(args); 
       return fragment; 
      } 
     } 

     @Override 
     public int getCount() { 
      return <YOUR_TAB_COUNT>; 
     } 
    } 

    public static class MyTabsFragment extends Fragment { 

     public static final String TAB_ID = "tab_id"; 

     @Override 
     public View onCreateView(LayoutInflater inflater, ViewGroup container, 
       Bundle savedInstanceState) { 
      int layoutId = -1; 
      switch (getArguments(getInt(TAB_ID))) { 
       case 0: 
        layoutId = R.layout.fragment_first_tab; 
        break; 
       case 1: 
        layoutId = R.layout.fragment_second_tab; 
        break; 
       ... 
       ... 
       ... 
       default: 
        layoutId = R.layout.fragment_default_tab; 

      } 
      View rootView = inflater.inflate(layoutId, container, false); 
      return rootView; 
     } 
    } 
} 

यह है कि से FragmentPagerAdapter या FragmentStatePagerAdapter का विस्तार। आपके लिए ViewPager द्वारा विभाजित किया जाएगा। आपको उन्हें खुद को जोड़ने की ज़रूरत नहीं है।

संबंधित मुद्दे