Introduction:

Sorry to say, Android8.0 oreo is out, I’m still learning the new features of 5.0, it seems to have to work harder, Material Design animation is really nice, check out the example here.

The main content

  • Android5.x UI design preliminary
  • Palette
  • Views and Shadows
  • Tinting and Clipping
  • Android Transition Animation
  • Material Design Animation effect
  • Toolbar
  • Notification

The specific content

Android5.x UI design preliminary

Android 5.x starts to use a new Design style called Material Design to unify the Design style of the entire Android system. Different from the previous Design, this time the Material Design will bring Android to a new height. At the same time, Google has launched a new Design guide on its official website, comprehensively explaining the entire implementation specification of Material Design.

Material morphology simulation

Google brings a real sense of space by simulating morphological changes in nature, closing lines and shadows, and spatial hierarchy between paper and paper.

More realistic animation

Use of large color blocks

Material Design uses a large number of high saturation, moderate brightness large color blocks to highlight the primary and secondary interface.

In addition, there are more Design styles, such as hover buttons, focus large images, frameless buttons, ripple effects and other new features. Readers who want to learn more about Material Design can visit the website: www.google.com/design/#res…

The Material Design theme

Material Design provides three default themes:

@android:style/Theme.Material (dark version)        
@android:style/Theme.Material.Light (light version)     
@android:style/Theme.Material.Light.DarkActionBar
Copy the code

The concept of Color Palette was also introduced, allowing developers to specify the Color of the system Palette.

You can create your own Color Palette theme by using a custom Style.

<resources>
    <! -- inherit from the material theme-->
    <style name="AppTheme" parent="android:Theme.Material">
        <! -- Main theme color-->
        <! -- your app branding color for the app bar-->
        <item name="colorPrimary">#BEBEBE</item>
        <! -- derker variant for thr status bar and contextual app bars-->
        <item name="colorPrimaryDark">#FF5AEBFF</item>
        <! --theme ui controls like checkBoxs and text fields-->
        <item name="colorAccent">#FFFF4130</item>
    </style>
</resources>
Copy the code

Palette

Android5.x uses the Palette to extract the color, allowing the theme to dynamically adapt to the hue of the current page.

Android has several built-in types for extracting colors:

  • Vibrant
  • Vibrant dark
  • Vibrant light
  • fraternal
  • Fraternal dark
  • A Muted light

To use the Palette, add a dependency to the Dependencies:

The compile 'com. Android. Support: the palette - v7:21.0.2'Copy the code

This can be done by passing a Bitmap object to the Palette and calling its Palette. Generate () static method or Palette. GenerateAsync () method to create a Palette.

The following example shows how to change the tone of the status bar and Actionbar by loading a soft tone for an image:

public class PaletteActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.palette);
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
                R.drawable.test);
        Create the Palette object
        Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() {
            @Override
            public void onGenerated(Palette palette) {
                // Get the corresponding hue from the Palette
                Palette.Swatch vibrant =
                        palette.getDarkVibrantSwatch();
                // Set the color to the corresponding component
                getSupportActionBar().setBackgroundDrawable(
                        newColorDrawable(vibrant.getRgb())); Window window = getWindow(); window.setStatusBarColor(vibrant.getRgb()); }}); }}Copy the code

View the renderings:

Views and Shadows

The most important feature of Material Design is the flattening of pseudo-object.

shadows

Android5.x adds the Z direction to the X and Y directions in the View.

The z value of View consists of two parts:

Z = elevation + translationZ;
Copy the code

You can usually set the View height of a View in an XML layout file:

android:elevation="XXdp"
Copy the code

Here is an example of the effect of different view heights:


      
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_margin="10dp"
        android:background="@mipmap/ic_launcher" />

    <TextView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_margin="10dp"
        android:background="@mipmap/ic_launcher"
        android:elevation="2dp" />

    <TextView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_margin="10dp"
        android:background="@mipmap/ic_launcher"
        android:elevation="10dp" />
</LinearLayout>
Copy the code

Effect:

You can also change the height of the view with code in the program:

view.setTranslationZ(xxx);
Copy the code

Generally, and can also animate properties to change view height:

if(flag){
    view.animate().translationZ(100);
    flag = false;
}else {
    view.animate().translationZ(0);
    flag = true;
}
Copy the code

Tinting and Clipping

Android5.x offers two new features for manipulating images: Tinting and Clipping.

Tinting

Note the tint and tintMode properties as follows:


      
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ImageView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_gravity="center"
        android:elevation="5dp"
        android:src="@mipmap/ic_launcher" />

    <ImageView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_gravity="center"
        android:elevation="5dp"
        android:src="@mipmap/ic_launcher"
        android:tint="@android:color/holo_blue_bright" />

    <ImageView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_gravity="center"
        android:elevation="5dp"
        android:src="@mipmap/ic_launcher"
        android:tint="@android:color/holo_blue_bright"
        android:tintMode="add" />

    <ImageView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_gravity="center"
        android:elevation="5dp"
        android:src="@mipmap/ic_launcher"
        android:tint="@android:color/holo_blue_bright"
        android:tintMode="multiply" />

</LinearLayout>
Copy the code

Effect:

Clipping (cutting)

Using Clipping, you first need to modify the outline using the ViewOutlineProvider, and then use the setOutlinProvider to apply the outline to the view.

The following is an example to understand Clipping:


      
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical">

    <TextView
        android:id="@+id/tv_rect"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginTop="20dp"
        android:elevation="1dp"
        android:gravity="center" />

    <TextView
        android:id="@+id/tv_circle"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginTop="20dp"
        android:elevation="1dp"
        android:gravity="center" />

</LinearLayout>
Copy the code

In code:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        View v1 = findViewById(R.id.tv_rect);
        View v2 = findViewById(R.id.tv_circle);
        / / get the Outline
        ViewOutlineProvider viewOutlineProvider1 = new ViewOutlineProvider() {
            @Override
            public void getOutline(View view, Outline outline) {
                // Modify outline to a specific shape
                outline.setRoundRect(0.0, view.getWidth(), view.getHeight(), 30); }};/ / get the Outline
        ViewOutlineProvider viewOutlineProvider2 = new ViewOutlineProvider() {
            @Override
            public void getOutline(View view, Outline outline) {
                // Modify outline to a specific shape
                outline.setOval(0.0, view.getWidth(), view.getHeight()); }};// Reset the shapev1.setOutlineProvider(viewOutlineProvider1); v2.setOutlineProvider(viewOutlineProvider2); }}Copy the code

Effect:

Android Transition Animation

Between the Activity of the jump, through overridePendingtransition (int inId, int outId) this method to switch the Activity to add some animation, effect is poor.

Android5.x provides three Transition type animations:

  • Enter: An enter transition animation determines how all views in the Activity enter the screen.
  • Exit: An exit transition animation determines how all views in an Activity exit the screen.
  • Shared Elements: A shared element transition animation determines the transition between two activities and how they share their views.

The entry and exit effects include:

  • Explode in and out of the middle of the screen, move the view.
  • Slide — Moves the view in and out of the edge of the screen.
  • Fade — changing the opacity of a view on the screen to add or remove a view.

The shared elements include:

  • ChangeBounds — Changes the layout boundaries of the target view.
  • ChangeClipBounds – Trim the bounds of the target view.
  • ChangeTransfrom – Changes the zoom and rotation Angle of the target view.
  • ChangeImageTransfrom – Changes the size and zoom of the target image.

For example, if ActivityA jumps to ActivityB and uses the three transition animations, change them in ActivityA:

startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
Copy the code

In ActivityB, you just need to set up the following code:

getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
Copy the code

Or set the following code in the ActivityB style file:

<item name="android:windowContentTransitions">true</item>
Copy the code

Then you can set the animation effect to enter ActivityB:

getWindow().setEnterTransition(new Explode());
getWindow().setEnterTransition(new Slide());
getWindow().setEnterTransition(new Fade());
Copy the code

Or set the animation away from ActivityB:

getWindow().setExitTransition(new Explode());
getWindow().setExitTransition(new Slide());
getWindow().setExitTransition(new Fade());
Copy the code

Renderings of the three normal switch animations:

Here’s how to use shared elements, starting with setting the attributes of the shared element in ActivityA:

android:transitionName="XXX"
Copy the code

Also set the same shared element attributes in ActivityB:

android:transitionName="XXX"
Copy the code

To use shared elements in code, start with a single shared element:

startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this,view,"share").toBundle());
Copy the code

Or if there are multiple shared elements in a view, use pair.create () to create multiple shared elements:

startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this, 
        Pair.create(view,"share"),Pair.create(fab,"fab")).toBundle());
Copy the code

Renderings of shared elements:

Material Design Animation effect

Ripple effect

Ripple effect: Click on the Ripple effect. You can set the Ripple background by code.

Android :background="? Android: attr/selectableItemBackground "/ / corrugated borderless android: background ="? android:attr/selectableItemBackgroundBorderless"Copy the code

Here is an example to illustrate both effects:


      
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/holo_blue_light"
    android:gravity="center"
    android:orientation="vertical">

    <Button
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="? android:attr/selectableItemBackground"
        android:text="Bounded ripple"
        android:textColor="@android:color/white" />


    <Button
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="? android:attr/selectableItemBackgroundBorderless"
        android:text="Unbounded ripple"
        android:textColor="@android:color/white" />

</LinearLayout>
Copy the code

Effect:

Similarly, you can declare a ripple through XML and use it in a layout file:


      
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="? android:colorPrimary">
    <item>
        <shape android:shape="oval">
            <solid android:color="? android:colorAccent" />
        </shape>
    </item>
</ripple>
Copy the code
<Button
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:background="@drawable/ripple" />
Copy the code

Effect:

Circular Reveal

The animation effects specific cash for a View in the form of a circular, revealed, through ViewAnimationUtils. CreateCircularReveal () to create animations, the code is as follows:

public static Animator createCircularReveal(View view, int centerX, 
int centerY, float startRadius, float endRadius) {
     return new RevealAnimator(view,centerX,centerY,startRadius,endRadius);
}
Copy the code

RevealAnimator is particularly simple to use, consisting mainly of a few key coordinate points:

  • CenterX The center point X at which the animation begins
  • The center point Y at the beginning of centerY’s animation
  • StartRadius animation startRadius
  • EndRadius indicates the endRadius of the animation

Let’s look at an example to see the use of the next RevealAnimator, which starts with creating a circle and square in XML:


      
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="? android:colorControlHighlight">
    <item>
        <shape android:shape="oval">
            <solid android:color="#738ffe" />
        </shape>
    </item>
</ripple>
Copy the code

      
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="? android:colorControlHighlight">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#738ffe" />
        </shape>
    </item>
</ripple>
Copy the code

Then use these two shapes in the layout file:


      
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center">

    <ImageView
        android:id="@+id/oval"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="@drawable/oval" />

    <ImageView
        android:id="@+id/rect"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="@drawable/rect" />

</LinearLayout>
Copy the code

The main program:

public class CircularReveal extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_circular_reveal);

        final View oval = findViewById(R.id.oval);
        oval.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Animator animator = ViewAnimationUtils.createCircularReveal(oval,
                        oval.getWidth() / 2, oval.getHeight() / 2, oval.getWidth(), 0);
                animator.setInterpolator(new AccelerateDecelerateInterpolator());
                animator.setDuration(2000); animator.start(); }});final View rect = findViewById(R.id.rect);
        rect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Animator animator = ViewAnimationUtils.createCircularReveal(rect, 0.0.0,
                        (float) Math.hypot(rect.getWidth(), rect.getHeight()));
                animator.setInterpolator(new AccelerateInterpolator());
                animator.setDuration(2000); animator.start(); }}); }}Copy the code

Effect:

View state changes Animation
  • StateListAnimator: View animation effect. Previously, Selector was used to modify the background to achieve feedback effect. Now Selector is supported to use animation effect.

Define a StateListAnimator in XML and add it to Selector:


      
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <set>
            <objectAnimator android:property="rotationX" 
        android:duration="@android:integer/config_shortAnimTime" 
        android:valueTo="360" 
        android:valuyeType="floatType" />
        </set>
    </item>
    <item android:state_pressed="false">
        <set>
            <objectAnimator android:property="rotationX"
        android:duration="@android:integer/config_shortAnimTime" 
        android:valueTo="0" 
        android:valuyeType="floatType" />
        </set>
    </item>
</selector>
Copy the code

Use directly in the layout file:

<Button
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:background="@drawable/anim_change" />
Copy the code

Special note: the Animator is to open, so must be used in the main code AnimatorInflater. LoadStateListAnimator () method, and through the setStateListAnimator assigned to View () method.

  • Allocation-selector: an animated effect selector that also works as a state change.

The first step is to have a set of state transition diagrams:

These image combinations are then defined in XML:

<animated-selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/state_on"
        android:state_checked="true">
        <bitmap android:src="@drawable/ic_done_anim_030" />
    </item>
    <item android:id="@+id/state_off">
        <bitmap android:src="@drawable/ic_plus_anim_030" />
    </item>
    <transition
        android:fromId="@+id/state_on"
        android:toId="@+id/state_off">
        <animation-list>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_000" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_001" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_002" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_003" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_004" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_005" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_006" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_007" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_008" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_009" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_010" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_011" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_012" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_013" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_014" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_015" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_016" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_017" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_018" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_019" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_020" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_021" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_022" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_023" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_024" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_025" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_026" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_027" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_028" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_029" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_plus_anim_030" />
            </item>
        </animation-list>
    </transition>
    <transition
        android:fromId="@+id/state_off"
        android:toId="@+id/state_on">
        <animation-list>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_000" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_001" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_002" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_003" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_004" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_005" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_006" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_007" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_008" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_009" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_010" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_011" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_012" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_013" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_014" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_015" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_016" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_017" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_018" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_019" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_020" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_021" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_022" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_023" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_024" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_025" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_026" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_027" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_028" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_029" />
            </item>
            <item android:duration="16">
                <bitmap android:src="@drawable/ic_done_anim_030" />
            </item>
        </animation-list>
    </transition>
</animated-selector>
Copy the code

Finally in the main program can be used:

public class AnimatedSelectorActivity extends AppCompatActivity {

    private boolean mIsCheck;
    private static final int[] STATE_CHECKED = new int[]{
            android.R.attr.state_checked};
    private static final int[] STATE_UNCHECKED = new int[] {};private ImageView mImageView;
    private Drawable mDrawable;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_animated_selector);
        mImageView = (ImageView) findViewById(R.id.image);
        mDrawable = getResources().getDrawable(
                R.drawable.fab_anim);
        mImageView.setImageDrawable(mDrawable);
    }

    public void anim(View view) {
        if (mIsCheck) {
            mImageView.setImageState(STATE_UNCHECKED, true);
            mIsCheck = false;
        } else {
            mImageView.setImageState(STATE_CHECKED, true);
            mIsCheck = true; }}}Copy the code

Effect:

Toolbar

The biggest difference between Toolbar and ActionBar is that the Toolbar is more free and controllable, which is why Google is gradually replacing ActionBar with Toolbar. To use Toolbar, you must import the AppCompat-V7 package and set the theme to NoActionBar. Use the following code to set it up:

<resources>

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <! -- Toolbar color -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <! Status bar color -->
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <! -- Window background color -->
        <item name="android:windowBackground">@android:color/white</item>
        <! -- add SearchView-->
        <item name="android:searchViewStyle">@style/MySearchView</item>
    </style>

    <style name="MySearchView" parent="Widget.AppCompat.SearchView" />
</resources>
Copy the code

Notification

Android5.0 optimizes Notification:

  • Long press Notification to display the message source.
  • When the screen is locked, the Notification message is displayed.

Notification is divided into three levels:

  • VISIBILITY_PRIVATE: indicates that it is displayed only when there is no lock screen.
  • VISIBILITY_PUBLIC: indicates that it will be displayed in any case.
  • VISIBILITY_SECRET: indicates that it is displayed in the case of security locks such as PIN and password and no lock screen.

Setting the level of Notification is as simple as adding:

builder.setVisibility(Notification.VISIBILITY_PUBLIC);
Copy the code

At the same time, Notificatio provides other methods:

  • Set the background color of the Notification
builder.setColor(Color.RED);
Copy the code
  • Set the category interface of Notification to determine the display position of Notification
builder.setCategory(Notification.CATEGORY_MESSAGE);
Copy the code