How to enable Split Action Bar?

匿名 (未验证) 提交于 2019-12-03 01:58:03

问题:

I want to create an android application which has 3 sliding tab panel and each of them will 5 button (save,new,delete,exit..).

What I want is exactly as follow:

I created sliding tab panel.And for 5 button, I added split action bar.But It works as normal split action bar.My AndroidManifest.xml is:

Where is my wrong?

回答1:

To implement splitActionBar:

Just add android:uiOptions="splitActionBarWhenNarrow" to your activity tag in theAndroidManifest.xml like this...

``

You can read more here and here

NOTE: It is available ONLY for handset devices with a screen width of 400dp.

To create a custom bottom toolbar:

If you want to set it for all devices, please check my answer (find a post starting with Creating custom bottom toolbar) here:

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

If you have any question please free to ask.

Hope it help



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!