Action Bar Tabs at the bottom?

后端 未结 2 448
走了就别回头了
走了就别回头了 2021-01-06 04:13

I\'m trying to place the action bar tabs at the bottom of my app, but I need some help with it (if it\'s even possible).

The code:

actionBar.setNavig         


        
2条回答
  •  南方客
    南方客 (楼主)
    2021-01-06 04:43

    There is another way to this but you have to use FrgamentTabHost.

    Here is the code. layout/activity_main.xml

    enter 
    
          
    
        
          
    
    

    You have to place TabWidget below the FrameLayout.

    layout/fragment_layout.xml

    enter code here
    
    
    

    MainActivity.java

    import android.os.Bundle;
    import android.support.v4.app.FragmentActivity;
    import android.support.v4.app.FragmentTabHost;
    
    public class MainActivity extends FragmentActivity {
        private FragmentTabHost mTabHost;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.activity_main);
            mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
            mTabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent);
    
            mTabHost.addTab(
                    mTabHost.newTabSpec("tab1").setIndicator("Tab 1", null),
                    FragmentTab.class, null);
            mTabHost.addTab(
                    mTabHost.newTabSpec("tab2").setIndicator("Tab 2", null),
                    FragmentTab.class, null);
            mTabHost.addTab(
                    mTabHost.newTabSpec("tab3").setIndicator("Tab 3", null),
                    FragmentTab.class, null);
        }
    }

    FragmentTab.java

    import android.os.Bundle;
    import android.support.v4.app.Fragment;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.TextView;
    
    public class FragmentTab extends Fragment {
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
        }
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View v = inflater.inflate(R.layout.fragment_layout, container, false);
            TextView tv = (TextView) v.findViewById(R.id.text);
            tv.setText(this.getTag() + " Content");
            return v;
        }
    }

    I hope it would help you.

提交回复
热议问题