0

If application with Action Bar run on tablet - there are menu button in right corner. But on smartphone this button don't show, because device has a hardware menu button, I think. I need impement similar behavior in my code to show my custom menu button only on tablet, and don't show it on smartphone? It is real? I don't want use action bar

Thanks

Dmitry
  • 369
  • 4
  • 18
  • Check this question: http://stackoverflow.com/questions/9044907/android-programatically-detect-if-device-has-hardware-menu-button#answer-9481965 but it's only for API >= 14 – Rendy Jul 06 '12 at 08:32
  • yes, I know this function, I'am using api 13 – Dmitry Jul 06 '12 at 17:53

1 Answers1

0

You can check if the device is tablet or smarphone, and inflate the option menu only if the device is tablet.

Suppose you have a method isTablet() that returns true if the device is tablet. Then you need to override the onCreateOptionMenu() and inflate the menu only if isTablet() returns true.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if(isTablet()){
        menuInflater.inflate(R.menu.menu_tablet, menu);
        return super.onCreateOptionsMenu(menu);
    }else{
        // do nothing
        return true
    }    
}

How to determine if a device is tabled or phone, you'll need to dig this article: http://developer.android.com/guide/practices/screens_support.html

Andy Res
  • 15,963
  • 5
  • 60
  • 96