how to make the actionbar transparent

2019-08-31 01:25发布

i am learning actionbar and created an actionbar with tabs .the following image shows the view !action bar demo

requestWindowFeature(Window.FEATURE_ACTION_MODE_OVERLAY);
    ActionBar ab=getActionBar();
    ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    ab.setBackgroundDrawable(new ColorDrawable(Color.MAGENTA));
    ab.addTab(ab.newTab().setText("Popular").setTabListener(this));
    ab.addTab(ab.newTab().setText("Latest").setTabListener(this));
    ab.addTab(ab.newTab().setText("Nearby").setTabListener(this));

They following are my queries :

  1. the tabs have shifted to a bar below the magenta color bar. is it due to space constraints of mobile.if a wish to add any item to this magenta bar with the tabs below how can add to it and then show the same pattern whether it is mobile or tablet.

  2. i want to make this tabs bar transparent so that i can see the text move behind it.i have tried to set its drawable as per code above but it has only changed of top bar but not the tabs bar.

  3. what is way to have a button on the magenta bar onclicking i have this screen shift to left and show another screen which has some links show up in a way that partly this current screen is also visible.i hope i am able to explain my point.

kindly clarify

1条回答
Summer. ? 凉城
2楼-- · 2019-08-31 01:56

Question 1: It's down to device space constraints. The first paragraph in the Android documentation for tabs in the action bar show that if there isn't room it will split the tabs to a separate bar.

http://developer.android.com/guide/topics/ui/actionbar.html#Tabs

Question 2: You need to set the drawable for the background and the stacked background of the action bar to your transparent drawable. (Edit: Links in Ye Lin Aung's comment show how to do that).

Question 3: It sounds like you are looking for a navigation drawer layout arrangement to me. The best place to start on this would be this link:

http://developer.android.com/training/implementing-navigation/nav-drawer.html

Edit: The pattern will work the same for both mobile and tablets (though you may want to have an xml for smaller screens that have a slightly thinner drawer sizes).

The android documentation in the link above states that the drawer width should be set in dp units and that the drawer height matches the parent view. The drawer width should be no more than 320dp so the user can always see a portion of the main content. This should allow most phones to view it in both portrait and landscape and still see some content.

查看更多
登录 后发表回答