Good day. As everyone knows, there is a StatusBar in the> = 21 API StatusBar . It follows from this that, with the same design, on devices <21 and >=21 elements will differ slightly due to the StatusBar value -a. Actually the question is: how to build the design of the application for different devices correctly, because the xml file does not put a condition for checking the version. I also don't really want to make up the software programmatically. Connoisseurs, your word! :)

    1 answer 1

    You can create several xml layouts that will be displayed depending on the version of Android. Actually, the quote directly from the site of developers:

    If the new XML attributes introduced in Android 5.0 (API level 21) are missing from the layouts created according to Material Design recommendations, such layouts are supported in previous versions of the Android OS. Otherwise, alternative layouts should be provided. You can also provide alternate layouts to customize the look of the application in earlier versions of Android.

    Create layout files for Android 5.0 (API level 21) in res/layout-v21/ , as well as alternative layout files for earlier versions of Android (in res/layout/ ). For example, res/layout/my_activity.xml is an alternative layout for res/layout-v21/my_activity.xml .

    To make the code more compact, define styles in res/values/ , change styles in res/values-v21/ for new APIs, and also use style inheritance by defining basic styles in res/values/ and specifying the inheritance of them in res/values-v21/ .

    • Thank you, for some reason I missed this moment ... - ivanovd422
    • Do I need to somehow programmatically describe whether the layout-v21 directory has been created or will the android check it? - ivanovd422
    • You have some kind of fragment or activit. When you apply your layout to them, Android will use the best one. If the API is 21 versions, then it will select res/layout-v21/ , if the version is lower, then the layout will be taken from res/layout . Before that, you need to create all the necessary directories yourself, and place your files there. - Vyacheslav Martynenko