Placing my ActionBar at the bottom

后端 未结 2 871
甜味超标
甜味超标 2020-12-03 12:11

I followed a tutorial on getting actionbars in my app. But even when I put android:uiOptions=\"splitActionBarWhenNarrow\" in my Manifest file it still keeps it

2条回答
  •  盖世英雄少女心
    2020-12-03 12:50

    According to this comment:

    How many menu items do you have in your ActionBar? The splitActionBarWhenNarrow option basically allows overflow into a second, "split" action bar on the bottom if your menu items won't fit at the top. If all your menu items fit at the top you won't see the split layout.

    If you would like to have a custom bottom toolbar, please check my answer to this question (added below):

    Creating custom bottom toolbar

    I've already created a simple app which should demonstrate you how to begin

    Creating a custom ViewGroup

    Here's my activity_main.xml layout file:

    
    
    
        
    
            
    
            
    
            
    
            
    
            
    
            
    
            
        
    
        
    
    

    As you can see my parent ViewGroup is RelativeLayout, which simply allows me to create a view at the bottom of screen.

    Notice that I set layout padding to zero (I think: setting layout margin to zero here is not necessary, the same effect). If you'd change it, the toolbar won't use full width and it won't stick with bottom of the screen.

    Then I added a Linear Layout with hardcoded height which is:

              android:layout_height="40dp"
    

    I wanted it, that my bottom toolbar would take full available width so I set it as match_parent.

    Next, I added some ImageButton views with images from Android library.

    There you have two possibilities:

    • if you really want to have a toolbar like in above example just remove in every ImageButton view this line:

            android:layout_weight="1"
      

    After removing weights and some buttons you would get a view pretty similar to expected:

    • if you want to take the full width and make every button with the same size use in your project weight as in this mine example.

    Now let's go to my AndroidManifest.xml

    
    
    
        
            
                
                    
    
                    
                
            
        
    
    

    In that file I'd added as you can see only one additional line:

             android:windowSoftInputMode="stateVisible|adjustResize">
    

    to make sure that device keyboard won't hide my custom bottom toolbar.

    From: How to add a bottom menu to Android activity

    I think in that way you can also put tabs at the bottom if needed.

    If you have any question please free to ask.

    Hope it help

提交回复
热议问题