Search code examples
androidandroid-actionbarandroid-resolution

How can I see if the device is a 7inch tablet


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?


Solution

  • 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.