2017-02-17 3 views
0

Ich versuche, tabView zu verwenden. Wenn ich die Seite wische, wischt die Seite nicht mit Tabs. Ich kann das Problem nicht herausfinden. Hilf mir bitte.Hinzufügen Swipe für die Seite zusammen mit Registerkarte Swipe in Android

Mein Aktivitätscode:

public class Notify extends AppCompatActivity implements ActionBar.TabListener{ 
    String contentText="I'm using android notification text." + "It's working fine, but the problem is that we have to create a big textview"; 
    TabLayout tabLayout; 
    private String[] frag={"Books","Canvas","Fragments","Needed"}; 
    ViewPager viewPager; 
    ActionBar a; 
    DemoCollectionPagerAdapter mDemoCollectionPagerAdapter; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.notification); 
     tabLayout = (TabLayout) findViewById(R.id.tab); 
     viewPager = (ViewPager) findViewById(R.id.viewPager); 
     a = getSupportActionBar(); 
     a.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 
     // tabLayout.addTab(tabLayout.newTab().setText("Books")); 
     //tabLayout.addTab(tabLayout.newTab().setText("Canvas")); 
     //tabLayout.addTab(tabLayout.newTab().setText("Fragments")); 
     //tabLayout.addTab(tabLayout.newTab().setText("Needed")); 


     for (String tab_name : frag) { 
      a.addTab(a.newTab().setText(tab_name) 
        .setTabListener(this)); 
     } 
     tabLayout.setSelectedTabIndicatorColor(Color.CYAN); 
     tabLayout.setupWithViewPager(viewPager); 
     viewPager.setAdapter(mDemoCollectionPagerAdapter); 
     mDemoCollectionPagerAdapter = new DemoCollectionPagerAdapter(getSupportFragmentManager()); 
     Log.i("TAG", "message"); 
     // getSupportActionBar().hide(); 

     viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { 

      @Override 
      public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 

      } 

      @Override 
      public void onPageSelected(int position) { 
       a.setSelectedNavigationItem(position); 
       mDemoCollectionPagerAdapter.notifyDataSetChanged(); 
      } 

      @Override 
      public void onPageScrollStateChanged(int state) { 

      } 
     }); 
    } 


    public void onClick(View view){ 
     NotificationCompat.Builder builder= new NotificationCompat.Builder(Notify.this); 
     builder.setContentTitle("Notify me"); 
     builder.setContentText(contentText); 
     builder.setSmallIcon(R.drawable.images); 
     builder.setTicker("Hey! You got it"); 
     builder.setAutoCancel(true); 

     Intent i=new Intent(Notify.this,Newactivity.class); 

     TaskStackBuilder stackBuilder=TaskStackBuilder.create(this); 
     stackBuilder.addParentStack(Newactivity.class); 
     stackBuilder.addNextIntent(i); 
     PendingIntent pendingIntent=stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT); 
     //Settings 
     Intent j=new Intent(Notify.this,Setting.class); 

     TaskStackBuilder stackBuilder_settings=TaskStackBuilder.create(this); 
     stackBuilder_settings.addParentStack(Setting.class); 
     stackBuilder_settings.addNextIntent(j); 
     PendingIntent pendingIntent_settings=stackBuilder_settings.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT); 
     //help 
     Intent k=new Intent(Notify.this,Help.class); 

     TaskStackBuilder stackBuilder_help=TaskStackBuilder.create(this); 
     stackBuilder_help.addParentStack(Help.class); 
     stackBuilder_help.addNextIntent(k); 
     PendingIntent pendingIntent_help=stackBuilder_help.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT); 


     builder.setContentIntent(pendingIntent); 

     builder.addAction(R.drawable.images,"Settings",pendingIntent_settings); 
     builder.addAction(R.drawable.images,"Help",pendingIntent_help); 


     Notification notification= builder.build(); 
     NotificationManager manager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE); 
     manager.notify(1234, notification); 
    } 

    public void bigText(View view) { 
     NotificationCompat.BigTextStyle style= new NotificationCompat.BigTextStyle(); 
     style.setBigContentTitle("Big Notification"); 
     style.bigText(contentText); 

     NotificationCompat.Builder builder= new NotificationCompat.Builder(this); 
     builder.setContentText(contentText); 
     builder.setContentTitle("Big Notification"); 
     builder.setSmallIcon(R.drawable.images); 
     builder.setAutoCancel(true); 
     builder.setStyle(style); 

     Notification notification= builder.build(); 
     NotificationManager manager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE); 
     manager.notify(567, notification); 

    } 

    public void bigpicture(View view) { 
     Bitmap bmp= BitmapFactory.decodeResource(getResources(),R.drawable.one); 
     NotificationCompat.BigPictureStyle style=new NotificationCompat.BigPictureStyle(); 
     style.setBigContentTitle("Big Picture"); 
     style.setBigContentTitle(contentText);style.bigPicture(bmp); 

     NotificationCompat.Builder builder= new NotificationCompat.Builder(this); 
     builder.setContentText(contentText); 
     builder.setContentTitle("Big Notification"); 
     builder.setSmallIcon(R.drawable.images); 
     builder.setAutoCancel(true); 
     builder.setStyle(style); 

     Notification notification= builder.build(); 
     NotificationManager manager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE); 
     manager.notify(111, notification); 

    } 

    public void inboxStyle(View view) { 
     NotificationCompat.InboxStyle style =new NotificationCompat.InboxStyle(); 
     style.setBigContentTitle("Inbox style"); 
     style.addLine("Line one"); 
     style.addLine("Line two"); 
     style.addLine("Line three"); 

     NotificationCompat.Builder builder= new NotificationCompat.Builder(this); 
     builder.setContentText(contentText); 
     builder.setContentTitle("Big Notification"); 
     builder.setSmallIcon(R.drawable.images); 
     builder.setAutoCancel(true); 
     builder.setStyle(style); 

     Notification notification= builder.build(); 
     NotificationManager manager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE); 
     manager.notify(279, notification); 

    } 

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


    } 

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

    } 

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

    } 
} 

Mein Adapter Code:

public class DemoCollectionPagerAdapter extends FragmentStatePagerAdapter { 

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

    @Override 
    public Fragment getItem(int position) { 
     switch (position){ 
      case 0: 
       BooksFragment myFragment = new BooksFragment(); 
       Bundle data = new Bundle(); 
       data.putInt("current_page", position+1); 
       myFragment.setArguments(data); 
       return myFragment; 
      case 1: 
       return new Fragment1(); 
      case 2: 
       return new Fragment2(); 
      case 3: 
       return new Fragment2(); 

     } 
     return null; 
    } 


    @Override 
    public int getCount() { 
     return 4; 
    } 

    private class BooksFragment extends Fragment { 
     @Nullable 
     @Override 
     public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 
      View root= inflater.inflate(R.layout.splashscreen,container, false); 
      ImageView imageView= (ImageView) root.findViewById(R.id.imageView); 
      return root; 
     } 
    } 
} 
+0

http://www.androidhive.info/2013/10/android-tab-layout-with-swipable-views-1/ überprüfe das –

+0

habe ich versucht das aber auch nicht zu können Finde das Problem heraus :( – Sairam

+0

kannst du deine xml? –

Antwort

0
<android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:tabMode="scrollable"/> 

Ich habe diese von hier. Neues Material Design http://www.androidhive.info/2015/09/android-material-design-working-with-tabs/ hoffe es hilft dir

+0

danke bro es löste mein swipe-problem. Ich muss daten in fragmenten hinzufügen. :) – Sairam

+0

Willkommen Bruder. Freue mich zu helfen :) :) :) –