Collapsible Toolbar - Make Fragment Footer Always Visible in Android

前端 未结 1 1175
深忆病人
深忆病人 2021-01-11 16:02

I am making an app that has a ProfilePage with three fragments - About | Posts | Gallery, and I am using a collapsible toolbar with user\'s image. My second and third fragme

1条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-11 16:16

    I had the same requirement for my one of apps. I just did workaround.
    Add your required layout in tab layout:

    
    
        
    
            
    
                
    
                
    
                    
                
    
            
        
    
        
    
            
    
            
        
    
        <-- Your required layout -->
        
    
            
    
            

    Add following code in your Tab activity:

    TabLayout tabLayout;    
    tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);//add your viewpager to TabLayout 
    
    tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
    
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            viewPager.setCurrentItem(tab.getPosition());
            LinearLayout l=(LinearLayout) findViewById(R.id.tab123);
            final EditText text=(EditText) findViewById(R.id.inputMsg);
            Button send=(Button) findViewById(R.id.btnSend);
    
            if (tab.getPosition() == 0) {
                l.setVisibility(View.GONE);
                System.out.println("About tab");
            } else if (tab.getPosition() == 1) {
                l.setVisibility(View.VISIBLE);
                System.out.println("Posts tab");
    
                send.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        String msg = null;
                        msg = text.getText().toString(); //get input
                        // Perform your desired task.
                    }
                });
            } else if (tab.getPosition() == 2) {
                l.setVisibility(View.VISIBLE);
                System.out.println("Gallery tab");
    
                send.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        String msg = null;
                        msg = text.getText().toString(); //get input
                        //Perform your desired task.
                    }
                });
            }
        }
    
        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
    
        }
    
        @Override
        public void onTabReselected(TabLayout.Tab tab) {
    
        }
    });
    

    0 讨论(0)
提交回复
热议问题