Android in-depth analysis of THEME.APPCOMPAT related issues (GO)

Source: Internet
Author: User

http://www.jianshu.com/p/6ad7864e005e

Let's take a look at this error first:

No resource found that matches the given name ‘@style/Theme.AppCompat.Light‘

For this mistake, I believe most of the Android developers have encountered, may have many friends through Baidu or Google has solved the problem, but most of the online only give a solution.

It is the so-called knowledge of it, know its why, this article will start from the problem, in-depth analysis of the cause of this problem, derived from a series of problems and solutions.

Android Support Library

The Android support Library, a set of code libraries that provide backward-compatible versions of Android Framew Ork APIs as well as features is only available through the library APIs.

There are many versions of the SDK version of Android, and the new SDK version contains a lot of new features, so Google officially provides the Android support Library package to ensure compatibility with the high-version SDK. By using this package, you can let apps with the latest SDK features run on top of the devices in API Lever 4 (that is, Android 1.6) and later.

    • V4 Support Library
      This packet is on top of API Lever 4 (i.e. Android 1.6) and later. It contains a lot of content and is used very extensively, for example: Fragment,notificationcompat,loadbroadcastmanager,viewpager,pagetabstrip,loader, Fileprovider and so on.
    • V7 Support Libraries
      This package is designed for API level 7 (i.e. Android 2.1) and above, but V7 relies on V4 for this package, V7 supports action bar and some theme compatibility.

      Note: v7 AppCompat Library
      The V7 AppCompat Library is a package included in the V7 support libraries, which adds a design pattern to the action Bar user interface and joins the material design, which is the most compatible package we use.

    • V13 Support Library
      This package is designed for API level 13 (ie Android 3.2) and later, generally we are not used, tablet development can be used, here is not too much to introduce.

    • V17 Preference support Library for TV
      Look at the name to know, this package is mainly for TV equipment and design.
Android Theme
    • Hoho Theme

Before 4.0 Android can be said to be no design, after 4.0 launched the Android design, since then the Android has a great improvement, and in the program implementation of the corresponding is the holo style, so you see there are similar Theme.Holo.Light, Theme.Holo.Light.DarkActionBar is 4.0 design style, but in order to let 4.0 before the version can also have this style how to do? This time will have to quote V7 package, so corresponding to have Theme.AppCompat.Light,Theme.AppCompat.Light.DarkActionBar, If the minimum supported version of your program is API14 (that is, Android 4.0), then you can not consider the compatibility of v7.

    • Material Design Theme

Android introduced the concept of material design in version 5.0, which is another big breakthrough on Android. corresponding to the implementation of the program has Theme.Material.Light, Theme.Material.Light.DarkActionBar and so on, But this style can only be used in the 5.0 version of the phone, if you apply material design before 5.0 how to do? The same reference APPCOMPAT-V7 package, this time of Theme.AppCompat.Light,Theme.AppCompat.Light.DarkActionBar is the theme of the material design that is relatively compatible.

Problem analysis

As a result, the following situations can lead to problems raised at the beginning of this article.

  • The project uses the Theme.appcompat theme, which is expressed as
    Project values directory Styles.xml file inside the style is
    <resources>  <style name="AppBaseTheme" parent="Theme.AppCompat.Light"></style> <style name="AppTheme" parent="AppBaseTheme"></style></resources>
    Androidmanifest.xml file inside
    android:theme="@style/AppTheme"
  • The minimum SDK supported by the project is less than API 14 (that is, Android4.0), as shown in
    Androidmanifest.xml file inside, minSdkVersion <14, for example

      <uses-sdk      android:minSdkVersion="8"      android:targetSdkVersion="23" />
  • The project did not import the Android-support-v7-appcompat Compatibility Pack.

Solution Solutions

Here are some workarounds:

  1. Since we haven't foundTheme.AppCompat.LightTheme, then I don't use this topic. The style in the Styles.xml file in the project Values,values-v11,values-v14 directory is now changed to
    <resources> <style name= "Appbasetheme" parent= "android:Theme.Light" > </style> << Span class= "Hljs-title" >style name= "Apptheme" parent=" Appbasetheme "> </style></resources>  
  2. If you don't find a Theme.AppCompat.Light theme, and we want to use the latest theme effects, there's another way to change the Androidmanifest.xml file minSdkVersion into 14, like

    <uses-sdk     android:minSdkVersion="14"     android:targetSdkVersion="23" />

    At this point, the project Values,values-v11,values-v14 directory of the Styles.xml file inside the style is changed to

    <resources> <style name= "Appbasetheme" parent= "Android:Theme.Holo.Light" ></style> <style name= "Apptheme" parent=" Appbasetheme "> </style></resources>  
  3. Of course, none of the above is the best approach, just a way of thinking. The best way is to import the Android-support-v7-appcompat library. The following are specific:
    3.1 Download the latest Android support Library via Android SDK manager.


    Img1.jpg


    After the download is complete, you can find the AppCompat library in the following directory

    android-sdk/extras/android/support/v7/appcompat

    3.2 Importing items from this directory into eclipse


    Img2.jpg


    3.3 Right click on our Android project, select Properties, choose Android on the left, click Add in the Library box below, and finally select Appcompat_v7, OK.
    At this point the problem is solved.


    Img3.jpg

    However, after importing appcompat_v7 to eclipse in the above 3.2, there may also be error prompts, such as
    appcompat_v7\res\values-v23\styles_base.xml:20: error: Error retrieving parent for item: No resource found that matches the given name ‘android:Widget.Material.Button.Colored‘.

This issue occurs because APPCOMPAT_V7 has been updated to the latest version and is higher than the SDK version of the build environment, when the SDK and compilation tools are updated to the highest version in the Android SDK Manager


Img4.jpg


After the upgrade is complete, right click on the Appcompat_v7 project, select Properties, select Project Build Target to the latest version, so OK.


Img5.jpg

Through the above analysis, I believe that friends will encounter appcompat related problems should no longer be a problem. Welcome to leave a message to discuss.



Wen/Koike laucherish (Jane book author)
Original link: http://www.jianshu.com/p/6ad7864e005e
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".

Android in-depth analysis of THEME.APPCOMPAT related issues (GO)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.