简体   繁体   中英

How do I create API level specific UI (a different UI for tablet and older versions of Android for the same app)?

I want my app display to be consistent across all android devices.

What code do I need to determine API level of user's device, and display appropriate UI Layout?

Example (pseudocode):

if Android 6 (API level 23) {
  Display UI-A
} 

if Android 10 (API level 29) {
  Display UI-B
}

I have perused documentation and other SO answers and there is no clear way to do this. I want my simple app to have a clean UI accross multiple API levels. This probably involves changing
res->layout files and AndroidManifest.xml, but I am unclear on how to do this properly. I want the UI to change based on device API level, with target level set as default.

You need to create different resources directories. So let us say that you need a layout for API 23 and a layout for API 28, you need to create two directories inside your resources folder, one with the name layout-v23 and the other with the name layout-v28 and you need to place your layouts in the respecting directories. You can read more about this here https://developer.android.com/guide/topics/resources/providing-resources#AlternativeResources

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM