I am using ActionBarSherlock to implement 4 tabs in an activity. The tabs display properly in portrait mode below the action bar and scrolling works as it should. When I switch to landscape mode, the tabs are placed in a spinner (they still function correctly). How can I force the tabs to display individually in landscape mode (either in the action bar or below)?
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar.Tab tab1 = getSupportActionBar().newTab();
tab1.setText("TAB 1 TEXT");
tab1.setTabListener(this);
getSupportActionBar().addTab(tab1);
ActionBar.Tab tab2 = getSupportActionBar().newTab();
tab2.setText("TAB 2 TEXT");
tab2.setTabListener(this);
getSupportActionBar().addTab(tab2);
ActionBar.Tab tab3 = getSupportActionBar().newTab();
tab3.setText("TAB 3 TEXT");
tab3.setTabListener(this);
getSupportActionBar().addTab(tab3);
ActionBar.Tab tab4 = getSupportActionBar().newTab();
tab4.setText("TAB 4 TEXT");
tab4.setTabListener(this);
getSupportActionBar().addTab(tab4);
How can I force the tabs to display individually in landscape mode (either in the action bar or below)?
By not using action bar tabs.
The behavior you are seeing is not tied to ActionBarSherlock. ABS is mirroring the behavior of the standard action bar, which will do the same thing. This is by design. It is also stupid, IMHO, but when I filed an issue, I was told that this was working as intended.
If you want your tabs to always be tabs, use any implementation other than action bar tabs, such as a ViewPager with a tabbed indicator.
This is the default behavior for the ActionBar.
https://code.google.com/p/android/issues/detail?id=24439
I saw this
https://groups.google.com/forum/#!msg/android-developers/2unF5lKfn64/iKUX7JbbOo4J
After adding tabs to ActionBar call setNavigationMode() for tab navigation mode, e.g.
Tab tabDemo=mTabsAdapter.addTab(bar.newTab().setText("ABC"),.Abc.class, null,"Abc");
bar.setNavigationMode(ActionBar.Navigation_mode_tabs);
It shows tabs in tabbed view mode.
I don't know if it works but you can try it.
You can also create a view with tabs instead of using the ActionBar tabs. I believe you have to use ViewPager or something like that.
Related
I have a bottom navigation view in Activity with 4 menu items (4 different fragments) that switches between them. The question is: how can I go from that menu fragment to another fragment that is not included in bottomnavigationview (deeper fragment hierarchy). I am using Android Navigation Framework to switch between fragments.
You could use a navigation drawer or tabs as well.
You can find more info here
I'm new to Android development. I get that a NavigationView is an AppBar (i think). What makes these two different? I want to create a custom "appbar/toolbar" with a centered logo and menu/settings button in the top right corner (instead of the standard left) which reveals a drawer.
I was going to ditch the built in appbar/toolbar all together and just create my own somehow and include button overlay which displays a drawer.
What would you do? Navigation view, app bar, or custom toolbar from scratch? I don't know what the standard is or what is acceptable. What is the difference between a navigationview and appbar. Thank you.
edit: I'm slowing realizing that an appbar is one feature within a navigation view, among others like a drawer layout, menu items etc... i think.
1. NavigationView
By using NavigationView, we can bind the menu directly with NavigationView. This is the benefit of the NavigationView. No need to create ListView and adapter with navigation drawer. By default we can get selector of item click. With menu we can change the color of icon of selected menu.
For more details :
1.https://developer.android.com/reference/android/support/design/widget/NavigationView.html
http://www.technotalkative.com/part-4-playing-with-navigationview/
2. AppBar
Appbar is for toolbar with scrolling effect. We can easily give the material design effect.
For more details :
1.https://developer.android.com/reference/android/support/design/widget/AppBarLayout.html
I made a TabLayout and it's work fine , but I want to disable change between tabs with slide and make it change tabs only by clicking the tab name
is there a way to do it?
Just use the TabLayout without the ViewPager. In your onTabSelected, you load the view or fragment you want into the page container.
I created an app and I use this example http://developer.android.com/training/implementing-navigation/lateral.html.
when I use the onCreateOptionsMenu(Menu menu) function and menu button create its shown in the first line and the line of the tabs is one behind it. How can I make the tabs and the menu button(three dots)
be in the same line?
I tried this
requestWindowFeature(Window.FEATURE_NO_TITLE);
also this
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
and this is only removed the title and the icon and now I have one empty line with menu button(...)
this its how its look now
Thanks
This is the expected behavior for non-tablet sized screens, so unless you roll your own ActionBar-isque implementation, you can't make the top ActionBar to go away as long as you have menu items.
However if you don't need the menu button, you can remove the top ActionBar entirely through
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
I have master detail layout in my app (see picture on the left):
I have navigation mode list set for actionbar (using it for filtering listview in second fragment):
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
I removed my activity title from actionbar with:
actionBar.setDisplayShowTitleEnabled(false);
The problem is that my drop down menu now appears above the first fragment (on the left side of the actionbar), as if it is refering to first fragment. This might confuse the user.
How can i place actionbar dropdown menu above second fragment?
there's no direct API to do what you want (move the spinner to the middle of the ActionBar)
Your best option to achieve something remotely similar to that is to create your own view with a spinner and user the setCustomView method from the actionbar.