195
CHAPTER 9: User Interface
Declare Restricted Screen Support
In some situations, you want to restrict your app by saying that some screen characteristics
just cannot be used. Obviously, you want to avoid such situations, but in case it is inevitable,
you can do so in AndroidManifest.xml.
Tell the app that certain activities can run in multiwindow modes
available on API level 24 (Android 7.0) or later. For that aim, use attribute
android:resizeableActivity and set it to true or false.
Tell certain activities they should be letter-boxed (have appropriate
margins added) above certain aspect ratios. For that aim, use attribute
android:maxAspectRatio and specify the aspect ratio as a value. For
Android 7.1 and older, duplicate this setting in the
element, as in android:value = "s.th." />.
Tell certain activities they should not be stretched above a certain limit
by using the largestWidthLimitDp attribute inside a
element.
Use more and elements and
attributes, as described in Chapter
2
.
Detect Device Capabilities
From inside your app, you can check for certain features as follows:
if(packageManager.
hasSystemFeature(PackageManager.FEATURE_...)) {
// ...
}
Here, FEATURE_... is one of the various constants from inside PackageManager.
An additional source of feature information is Configuration. In Kotlin, from inside an
activity, you can obtain the configuration object via the following:
val conf = resources.configuration
From there, obtain information about the color mode in use, available keyboards, screen
orientation, and touchscreen capabilities. To get the screen’s size, you can write the
following:
val size = Point()
windowManager.defaultDisplay.getSize(size)
// or (getSystemService(Context.WINDOW_SERVICE)
// as WindowManager).defaultDisplay.getSize(size)
val (width,height) = Pair(size.x, size.y)
Do'stlaringiz bilan baham: |