Pop-up window series: Where is AppCompatDialog sacred?

  • In the previous project catering system, the implementation of pop-up windows often inherited from AppCompatDialog instead of the Dialog class. So why use the AppCompatDialog class instead of directly inheriting from the Dialog class?
  • The AppCompatDialog class comes from the appcompat-v7 package, which is often referred to as support-v7, so what problem does this support-v7 solve? Look at the following passage:

The App we develop needs to support minSdkVersion=9 and targetSdkVersion=11. The ActionBar class provided by android 3.0 (API level 11) is used in the project, and the apk is successfully compiled with compileSdkVersion=11. This apk runs perfectly on android 3.0 devices, but the app crashes on devices with android 2.3 (API leve 9) and reports an error that ActionBar cannot be found.
This is easy to understand, because before Android 3.0, there was no ActionBar class. In order to avoid the embarrassment that apps developed using the latest SDK can only run on devices equipped with the latest system, the official put forward the newly added interfaces in the new version of the system framework and put them in the Android Support Library (support package). In the above situation, you can use the ActionBar class with the same function in the support package. This support package will be packaged into the App, so that the App that uses the functions on the new version of the SDK can also be compatible with the previous device of the old system version.

To sum up, let the functions in the app that are only available on the new system can also be displayed normally on the old system.

  • Another problem is that many blogs mentioned that the appcompat-v7 package was launched at the google io developer conference in 2014, but I did not find direct evidence. The Material Design design specification was launched at the Google IO Developer Conference in 2014, which is true. So, is there any relationship between appcompat-v7 and Material Design?

The only possibility is Theme, which is the theme settings of the Activity and Application classes. Because the pop-up window wants to achieve the effect of Material Design, you need to set the corresponding style or theme, for example:

Android introduced the concept of Material Design in version 5.0. The corresponding program implementations include Theme.Material.Light, Theme.Material.Light.DarkActionBar, etc., but this style can only be applied to mobile phones of version 5.0 and above. What should I do if Material Design is applied before 5.0? The answer is to quote the appcompat-v7 package. At this time, Theme.AppCompat.Light and Theme.AppCompat.Light.DarkActionBar are the corresponding Themes that are compatible with Material Design.

The other differences between AppCompatDialog and Dialog are still to be studied. Continue to study!

Guess you like

Origin blog.csdn.net/zhangjin1120/article/details/113790048
Recommended