Adapt layout to Android platform or API level

后端 未结 3 1503
滥情空心
滥情空心 2020-12-05 01:48

For the application I am currently developing, I need to adapt the layout of the different activities to the user\'s Android API level.

Is there a way to do this?

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 02:37

    As Andrew Koester said you can use the different version folders, but I found this to be a lot of work because it would not fall back to the default layout. If you used layout-v14, it will work,but any api after 14 will also have this layout and you must use another layout-v? to override it again. It all depends on what your doing, but I found if your doing a lot of stuff programmatically this works wonders:

    if(Build.VERSION.SDK_INT == Build.VERSION_CODES.ICE_CREAM_SANDWICH || Build.VERSION.SDK_INT == Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1){
                //ex. if ics is met then do this
    
            }else{
                //if api is not ics then do this
            }
    

提交回复
热议问题