Is it possible to define different menus for different screen sizes? I've tried adding folders res/menu-large and res/menu-xlarge, but the menu xmls I place here have no effect on my xlarge tablet.
Not a real answer, just an idea, but too long for a comment:
I don´t think that this is supported, it seems that this is not documented. But a possible idea is, to set booleans on different values. For example, you could set som res-values folder:
res/values-xlarge res/values-large res/values-sw600dp
and so on. In that values, You could declare a boolean:
<resources>
<bool name="isXLarge">true</bool>
</resources>
or
<resources>
<bool name="isLarge">true</bool>
</resources>
etc...
Then create different menu layouts which You could start if one of the values are true.
menu_large.xml menu_xlarge.xml menu_sw620dp.xml
And at createOptionsMenu:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
boolean xlargeValue = getResources().getBoolean(R.bool.isXlarge);
boolean largevalue = getResources().getBoolean(R.bool.isLarge);
boolean tabletValue = getResources().getBoolean(R.bool.sw620dp):
if(xlargeValue==true){
inflater.inflate(R.menu.menu_xlarge, menu);
}else if(largevalue==true){
inflater.inflate(R.menu.menu_large, menu);
}else if(tabletValue==true){
inflater.inflate(R.menu.menu_sw620dp, menu);
}
return true;
}
I have never tested it, because the generated menu looks good on all screen sizes if you set different drawables to the drawable folders.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With