New SupportLibrary

With the release of the new Support library for Android Oreo

features

  • 8.0 the corresponding SupportLibrary26
  • 8.1 the corresponding SupportLibrary27
  • They support a minimum of API 14 (for devices 4.0 and later)
  • 1400 methods were deleted
  • Mark 30 classes and 400 methods as deprecated

use

Repositories dependencies Google () {} {the compile com. Android. Support: aappcompat. V7:26.0.1}Copy the code

New features

The following are new Oreo features that are available through the new Support library on older Android devices

Fonts in XML

Fonts can be a new resource type

use

2. Copy the font files (such as dacing. TTF) to this directory. 3. Android: fontFamily= "@font/lalala" Style: android: fontFamily= "@font/lalala" Style: android: fontFamily= "@font/lalala" <item name=" Android :fontFamily">@font/lobster</item> Typeface typeface = ResourcesCompat.getFont(context, R.font.myfont);Copy the code

The font family, for example,

<? xml version="1.0" encoding="utf-8"? > <font-family xmlns:android="http://schemas.android.com/apk/res/android">
<font
     android:fontStyle="normal"
     android:fontWeight="400"
     android:font="@font/lobster_regular" />
<font
     android:fontStyle="italic"
     android:fontWeight="400"
     android:font="@font/lobster_italic" />
</font-family>
Copy the code

Font downloadable

We can choose not to package font resources into APK, but to download them. The benefits of this are:

  1. Reduce the APK volume
  2. This improves the application installation success rate
  3. Multiple apps can share the same font resource

Principle: App requests font resources to the corresponding FontProvider (such as Google Play) through fontContract, as shown in the figure

Emoji compatible library

Principle: Use the emoticons compatibility library. When the latest emoticons are not supported by the current system, load new emoticons through the compatibility library, as shown in the figure

Use:

  1. Configuration: Download configuration (similar to fonts) or bundle configuration (will increase APK 7MB)
  2. Initialize in onCreate
  3. Use EmojiTextView instead of TextView, use EmojiButton instead of Button, etc

TextView automatically resizes the text

Support26 library provides automatic adjust the TextView text size, android. Support. The v4. The widget package TextViewCompat function similarly, if you need to support 4.0 the following equipment, can consider to use v4 package

Note: It is not recommended to set the width or height to WRAP_content if you use auto-resizing text, which can cause unexpected errors

There are three ways to use the namespace (for support, use namespace) :

  • TextView automatically resizes text by default
We can pass it in codesetAutoSizeTextTypeWithDefaults (AUTO_SIZE_TEXT_TYPE_NONE) to shut down, this property can also be set in the XML file <? xml version="1.0" encoding="utf-8"? > <TextView android:layout_width="match_parent"
       android:layout_height="200dp"
       android:autoSizeTextType="uniform" />
Copy the code
  • The details of automatic resizing behavior are controlled by maximum and minimum values and granularity
Dynamically set in codesetAutoSizeTextTypeUniformWithConfiguration(int autoSizeMinTextSize, int autoSizeMaxTextSize, int autoSizeStepGranularity, int Unit) XML file set <TextView Android :layout_width="match_parent"
   	 android:layout_height="200dp"
   	 android:autoSizeTextType="uniform"
   	 android:autoSizeMinTextSize="12sp"
   	 android:autoSizeMaxTextSize="100sp"
   	 android:autoSizeStepGranularity="2sp" />
Copy the code
  • We can also specify a specific value for resizing
Dynamically set in codesetPresetSizes AutoSizeTextTypeUniformWithPresetSizes (int [], int unit) set in the XML file, First in the res/values/arrays. Xmlres/values/arrays. The XML to create an array < resources > < array name ="autosize_text_sizes"> <item>10sp</item> <item>12sp</item> <item>20sp</item> <item>40sp</item> <item>100sp</item> </array> </resources> references this array  <TextView android:layout_width="match_parent"
       android:layout_height="200dp"
       android:autoSizeTextType="uniform"
       android:autoSizePresetSizes="@array/autosize_text_sizes" />
Copy the code

VectorDrawableCompat

Added the Android: fillType attribute to increase support for fill-rule in SVG

AnimatedVectorDrawableCompat

Added XML – based path distortion and interpolation

Physics-based DynamicAnimation

Similar to MaterialDesigh, which simulates animations in the real world, there are currently two physics-based animations

  • FlingAnimation (Simulates friction, has an initial speed, gradually slows down to 0)
FlingAnimation(view,DynamicAnimation.TRANSLATION_Y).apply{
    setStartVelocity(5000f); // Pixels per second friction = 1.5f; // start(); }Copy the code
  • SpringAnimation(analog spring, can set damping ratio, stiffness, final stop position, etc.)
SpringAnimation(view,SpringANimation.TRANSLATION.Y,0f).apply{
   spring.apply{
     dampingRatio = SpringForce.DAMPING>RATIO>LOW>BOUNCY;
     stiffness = SpringForce.STIFFNESS_LOW;
     finalPosition = 0f;
   }
    setStartVelocity(20000f);
    start();
}
Copy the code

After #

Attached with Oreo and Android Studio some of the features of the video