Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Positioning OK/Cancel buttons so that they mimic the layout in dialogs

Tags:

android

layout

As some of you might have noticed, Android changed the order in which the OK/Cancel buttons are displayed in dialogs after ICS (see this issue). The change might make sense, I'm not contesting it. My question is, how are you guys dealing with applications that support both the new theme (because of the action bar) and the "original" theme? How can we reconcile the order in our layouts with the order in the Dialog?

I tried looking into the dialog code, but it's not doing anything special, the order is determined in the layout files (which is styled different for Holo). Has anyone created a fragment or widget that takes this into account?

like image 640
dmon Avatar asked Apr 24 '12 16:04

dmon


1 Answers

You can put an alternative layout in layout-v14 with the buttons positioned as in ICS. In fact, that is what lint will advise you to do when you run it on your project. Quote:

Layout uses the wrong button order for API >= 14: Create a layout-v14/layout.xml file with opposite order: OK button should be on the right (was "OK | Cancel", should be "Cancel | OK")

You can use DialogFragment to create dialogs with custom layouts.

like image 180
Nikolay Elenkov Avatar answered Nov 14 '22 03:11

Nikolay Elenkov