0

I am trying to set up tabs in my actionbar but on a 7inch tablet the tabs dont fit so they get pushed into a dropdown view in the actionbar.

They show up in tabs if I abbreviate some of the words in the tabs but I dont want that to always be the case because on a 10inch tablet its fine.

So how can I see if the current device is a 7inch tablet so that I know I have to abbreviate the tab text?

tyczj
  • 71,600
  • 54
  • 194
  • 296

2 Answers2

1

You should read Supporting Multiple Screens page in the Android Developer's guide.

You shouldn't detect and correct for different types of screens based on physical size. What does that mean for your assets? A 7-inch tablet could very well have the same number of pixels as a phone, and would both would have the same UI problems. What you want is to target different pixel densities.

Here are some rough guides from that page:

  • 320dp: a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800
  • hdpi, etc). 480dp: a tweener tablet like the Streak (480x800 mdpi).
  • 600dp: a 7” tablet (600x1024 mdpi). 720dp: a 10” tablet (720x1280
  • mdpi, 800x1280 mdpi, etc).

You can use these values to target specific densities by using targeted asset folders such as res/layout-sw600dp/main_activity.xml.

Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120
0

I am trying to set up tabs in my actionbar but on a 7inch tablet the tabs dont fit so they get pushed into a dropdown view in the actionbar

This has little to do with "7inch tablet". Android will choose, when it wants to, based on its own rules, whether to display action bar tabs as tabs or as a drop-down. This is based on a variety of factors, including orientation.

on a 10inch tablet its fine.

Have you tested it on every tablet ever manufacturered? If not, how can you be certain of this claim?

Not to mention that there will be new devices manufactured in the future with possibly different characteristics. And, of course, Android can change its algorithm for determining when to switch between tabs and drop-down lists.

If you do not want your tabs be switched into a drop-down list, then do not use action bar tabs. Use:

  • ViewPager with PagerTabStrip, or
  • ViewPager with the tab indicator from the ViewPagerIndicator library, or
  • FragmentTabHost
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491