On the problem of quoting Theme.appcompat theme error

Source: Internet
Author: User

Establishment of the V7 package Libraries (Library) project for other projects
    1. Chapter: Those pits before using support-v7 Actionbar
      1. 1. Establish the V7 package libraries (Library) project for other project references
      2. 2. V7 Library project Themes_base.xml related file error problem
      3. 3. Questions about quoting Theme.appcompat theme error

Prior to the previous 3.0 version to use Actionbar, must use the foreign Daniel wrote actionbarsherlock this open source project. After the 2013 Google I/O conference, Google officially added Actionbar to the ANDROID-SUPPORT-V7 package, Started to let the 2.1 version support Actionbar, since then the most popular Android open source project Actionbarsherlock can exit the historical stage.

It is easy to use the V7 bag in Actionbar, but there is one place to pay attention. Some people may have just started to import Android-support-v7-appcompat.jar into the project, but will error when setting activity Theme, indicating "@style/theme.appcompat" is not found. This is because we want to import V7 and resource files, just import V7 package is not enough.

Specific steps to use under Eclipse are (from the Android website):

Create a library project based on the Support library code:

  1. Make sure has downloaded the Android support Library using the SDK Manager.
  2. Create a library project and ensure the required JAR files is included in the project ' s build path:
    1. Select File > Import.
    2. Select Existing Android Code into Workspace and click Next.
    3. Browse to the SDK installation directory and then to the support Library folder. For example, if is adding the appcompat project, browse to /extras/android/support/v7/appcompat/ .
    4. Click Finish to import the project. For the V7 AppCompat project, you should now see a new project titled Android-support-v7-appcompat.
    5. The new library project, expand libs/ the folder, right-click each .jar file and select Build Path > Add to Bui LD Path. For example, when creating the V7 AppCompat project, add both the and android-support-v4.jar files to the android-support-v7-appcompat.jar build path.
    6. Right-click the project and select Build path > Configure build Path.
    7. In the Order and Export tab, check the .jar files you just added to the build path, so they is available to Pro Jects that depend in this library project. For example, the appcompat project requires your to export both the android-support-v4.jar and android-support-v7-appcompat.jar files.
    8. Uncheck Android Dependencies.
    9. Click OK to complete the changes.

You are now having a library project for the your selected support library so you can use with one or more application projects.

ADD the library to your application project:

    1. In the project Explorer, right-click your project and select Properties.
    2. In the Library pane, click Add.
    3. Select the Library project and click OK. For example, the appcompat project should is listed as Android-support-v7-appcompat.
    4. In the Properties window, click OK.

Once your project is a set up with the support library, here's how to add the Action bar:

    1. Create your activity by extending ActionBarActivity .
    2. Use (or extend) one of the Theme.AppCompat themes for your activity. For example:

Now your activity includes the action Bar is running on Android 2.1 (API level 7) or higher.

On API level one or higher

The action Bar is included with all activities Theme.Holo so use the theme (or one of it descendants), which is the default th The EME when either the targetSdkVersion or minSdkVersion attribute are set to "11" or higher. If you don't want the action bar for a activity, set the activity theme to Theme.Holo.NoActionBar .

To put it simply, it is:

    1. Upgrade the SDK support Library first;
    2. Create a new project based on the/extras/android/support/v7/appcompat/in the SDK directory;
    3. This project Libs under the V4, V7 package build Path;
    4. Configure Build Path.
5.0-based V7 Package Library project

The project can then be referenced by other projects.

2) V7 Library project Themes_base.xml related files error problem

If you use the latest SDK, you might have an error with the new V7 Library project:

The error message might look like this:

Error:error Retrieving parent for item:no Resource found that matches the given name ' Android:TextAppearance.Material '. E Rror:error Retrieving parent for item:no Resource found that matches the given name ' android:widget.material.* ' Error:er Ror:no resource found that matches the given name:attr ' android:actionmodesharedrawable '.

The workaround is simple:

The only thing are the project.properties file of the Android-support-v7-appcompat and change the TA Rget from target=android-19 to target=android-21. Afterwards just do a Project--and clean ... so, the changes take effect.

is to change the build environment to SDK 21 on the line. Two methods, open project.properties, change the target=android-7 (or other) to target=android-21; You can also right-click on the project name, tap Android, modify project Build Target is Google APIs 21.

Then clean, the project error will disappear.

3) questions about quoting Theme.appcompat theme

When the V7 Library project is set up, and other projects are quoted, you think there should be no errors, but run an error, probably reported such a mistake:

1 java.lang.RuntimeException: Unable to start activity ComponentInfo{jh.com.testandroidlayout/jh.com.testandroidlayout.navigator.NaviViewPagerActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) withthisactivity.

You need to use a theme.appcompat Theme (or descendant) with the this activity.

This error is obvious, and very simple, originally inherited from the Actionbaractivity class must specify a fixed centralized theme style, and these theme style is required to import V7 in the AppCompat Lib Library project, compiled and then referenced to use.

Open the Androidmanifest.xml of your project and find the Android:theme= "@style/xxx" and change it to the plan provided in the V7 package. Like what:

1 android:theme="@style/Theme.AppCompat"黑色系
2 android:theme="@style/Theme.AppCompat.Light"浅色系

More color schemes You can go to browse by yourself in the Application tab page.

A more detailed discussion on the StackOverflow: http://stackoverflow.com/questions/21814825/ You-need-to-use-a-theme-appcompat-theme-or-descendant-with-this-activity

On the problem of quoting Theme.appcompat theme error

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.