Learn to use material design controls (I)
The material design support library released by Google has a great impact on our app design. If we redesign the app, the support library should be directly upgraded from V4 to v7. We can use the toolbar instead of the actionbar, and introduce new controls such as recycleview and snakebar.
I wrote a demo to learn how to use these new controls.
Create a new project and add dependent packages
We use Android studio to develop this demo, create a new project in Android studio, modify the build.gradle file of APP module, and change the compilesdkversion and targetsdkversion to 21, because the material design support library requires Android 5.0 or above as the compilation SDK.
At the same time, add the related dependent package design and recyclerview support package.
New layout
New activity_ Main.xml, in which we add toolbar and recyclerview
New activity
The new mainactivity inherits from appcompatactivity
Join toolbar
Using recyclerview
Recyclerview is used to replace listview. It encapsulates some processing of viewholder. However, recyclerview does not have setonitemclicklistener method and needs to be implemented by itself.
Using snackBar
The use of Snackbar is similar to Toast. I invoke Snackbar in RecyclerView's Item click event to display text in TextView.
The source code of the project has been released to GitHub, and other controls will be added slowly in the future.
Source address: materialdesignexample
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.