I have an app I was working on. We wanted to upgrade the minSDK from Froyo to IceCream Sandwich (14) so we could use some of the newer features including the Holo Dark theme.
On StackOverflow we found steps for editing the build.gradle (Module: app) file and changed the minSDK to 14. We resync'd as requested. Then rebuilt the app. All compiled fine and ran on our connected device which is running 4.4.4
I then went to the styles.xml file and changed the AppTheme accordingly.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to
<style name="AppTheme" parent="android:Theme.Holo">
also as recommended here.
I rebuild the app and it compiles fine. When it attempts to run on our connected device, I get a "The Application has Stopped" immediately.
I looked in the LogCat (per a Comment) and once I figured out what I was looking at, I found this line:
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
Not sure what that means.
Am I missing something either on the "SDK" change or on the Theme?
Thanks
Pete
Hey can you show your code for said activity? Especially the declaration. I've had this error before and it might have to do witht the fact that you aren't extending (extends) the right actionbar in your activity's declaration.
For example :
extends ActionBarActivity
Related
I am experiencing a problem while trying to see the preview of layout xml files in Android Studio. There is a string with the content: android...CoordinatorLayout or android...ActionBarOverlayLayout in the middle of the preview screen.
I tried a few things I found while searching for a solution:
1) Cleaning the project
2) Invalidating Cache/ Restart
3) Changing the API level of the editor window.
I am not sure if this behaviour first appeared after switching to Android Studio 3.
android.support.v7.internal.widget.ActionBarOverlayLayout could not be instantiated
Had the exact same problem. I got rid of it by changing res/values/styles.xml to
<!-- Base application theme. -->
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
The problem seems to be a bug in Android Studio 3.0.
Everything went back to normal when I targeted SDK version 26.
I'm trying to use the CoordinatorLayout in my Xamarin.Android app. I've been using a custom theme with Theme.Material.Light as its parent, which worked fine before I added the CoordinatorLayout. When I add it, I get an error telling me I have to use a Theme.AppCompat theme, but as soon as I do the app fails to build and gives me the following error:
/{project directory}/Resources/values/Styles.xml(0,0):
Error APT0000: Error retrieving parent for item:
No resource found that matches the given name
'#android:style/Theme.AppCompat'. (APT0000) (TnpApp.Android)
This answer suggests installing the major version of the support library that matches the Android SDK I'm using. I've tried this (I think I did everything correctly), but it doesn't help.
Does anyone have any ideas?
I'm using Xamarin Studio on Mac.
UPDATE 1
I tried the following code in MainActivity.cs in a clean Xamarin.Android project, and build fails with the same error.
namespace ThemeTest
{
[Activity(Label = "ThemeTest", MainLauncher = true, Icon = "#mipmap/icon", Theme = "#android:style/Theme.AppCompat.Light")]
public class MainActivity : Activity
{
// ...
}
}
UPDATE 2
I removed all the folders from /user/.local/share/Xamarin except for Mono for Android and zips as suggested in this answer. I closed Xamarin Studio and reopened it. I tried to deploy the app, and Xamarin reinstalled all the packages but the build failed with the original error.
I was able to fix this problem by simply removing #android:style/ from the style element's parent tag in my Styles.xml file. So what looked like this...
<style name="MyCustomTheme" parent="#android:style/Theme.AppCompat">
Now looks like this...
<style name="MyCustomTheme" parent="Theme.AppCompat">
I'm shocked the solution is this simple, but it works. :) I got the idea from this code.
I'm developing in Visual Studio 2015/Xamarin and saw this same problem. While I still don't understand the cause or the fix for this problem, this thread did point me in the right direction which seems to have more to do with resaving styles.xml (for my development environment) than anything else.
My styles.xml did not have #android:style/ and I still had the error mentioned above. As described in another proposed solution, I added
<style name="MyCustomTheme.Base" parent="Theme.AppCompat" />
before <style name="MyCustomTheme" parent="Theme.AppCompat">, saved styles.xml and rebuilt my project without errors. I then removed
<style name="MyCustomTheme.Base" parent="Theme.AppCompat" />,
resaved styles.xml and rebuilt with no errors. Visually, my styles.xml is unchanged, but the error is gone.
If you recently installed a google play service related package (firebase for example , but there are many others) , it is possible that this installation messed up with your CSproj and your package.json files (look at your version control history to see if these files were changed), and modified your target api version : Going from target Api 25 to Target 26 for exemple etc.
If this is the case , you should adresse this problem one of two ways :
make sure you download the sdk version that you are now targeting , to do this , go to TOOLS > SDK manager.
or revert back to your old target , by discarding the change the package made to you csproj and package.json files and clean and rebuild.
I'm trying to learn Android through the tutorials at TheNewBoston.com.
In the tutorial, I'm supposed to switch to the material light theme. That's when I get the error. It says:
Missing styles. Is the correct theme chosen for the layout?
Here's a screen shot:
Here's what I've tried:
I've tried switching out of Android API 23, N preview for a lower
API
I've tried changing code in the styles.xml file from
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
I've tried invalidating the cache and restarting.
Nothing seems to be working. I'm very new at Android and just want to get the IDE set up correctly. I also get this message on startup and I think it's related to the error:
Change your layout Preview from API N to API 23. also select target and compile sdk version 23.
Change Compile sdk version and Build SDK version
Have you added this line to your build.gradle file under dependencies
compile 'com.android.support:appcompat-v7:23.2.1'
Note that the support version number might be higher for you. Add below line too to your depedencies
compile 'com.android.support:design:23.2.1'
In theme dropdown at the top of the graphical display of layout. change Theme.
check your theme in style than choose it in the layout too
OR
changed from Holo to Theme and the layout displayed and error disappeared.
check this answer for more detail
Reinstalling Android Studio and right-clicking the shortcut to run the program as administrator sorted out the problem.
I am just a beginner to android app development. When i created a new project on Android Studio 1.1.0,
it gives up this error
"rendering problems
The following classes could not be found android.support.v7.internal.widget.ActionBarOverlayLayout"
Now i have searched about this on google, and i found possibly 3 solutions given by most of the people.
They say:
Either change the api (from preview window pane) from 22 to 21, or
Change the App Theme from "Project Theme" to any other theme.
be sure to have imported right appcompat-v7 library in your project structure -> dependencies,
Refer these steps:
Add the support library feature project identifier to the dependencies section. For example, to include the appcompat project add compile "com.android.support:appcompat-v7:18.0.+" to the dependencies section, as shown in the following example:
dependencies {
...
compile "com.android.support:appcompat-v7:18.0.+" }
Note: My android support lib is up-to-date (installed it using SDK Manager).
Following first two steps, removed the error. But I feel that these are not the permanent solutions, the Second step seems just like a temporary workaround. I have doubts about the First step also, that if to remove the error, we change api from 22 to 21, then at the end, our app wont work in Android 5.1.1(API 22), it would be restricted to Android 5.0.1 and below only (API 21). Are my doubts valid?
Regarding the third step, is it the permanent solution to this problem?
P.S : Sorry for mismatching tags, wasn't allowed to add exact tags due to site reputation
Fix res/values/styles.xml like so:
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar"/>
Detailed explanation as requested: Theme.AppCompat.Light.DarkActionBar is a subclass of the superclass Base anyway. Ctrl+click (Android Studio) on it and you will be taken to the source:
<style name="Theme.AppCompat.Light.DarkActionBar" parent="Base.Theme.AppCompat.Light.DarkActionBar" />
We didn't change anything, we just defined it more precisely.
This is a known bug since Android Studio build 1.1 (it is also still in 1.2 and 1.3 preview). Switching the preview's API level from 22 to 21 fixes the for most people. While waiting for a fix you could try it as well.
Originally answered here : Rendering problems in Android Studio v 1.1 / 1.2
Just reposting
Modify src/res/values/styles.xml
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar"></style>
Then select API22, you'll find this problem fixed!
After this error, I'm using :
API-22 Android 5.1.1 and still this problem exist.But you can at the top of the android studio toolbar, Choose:
Material Light -> Material Light
and then you can see the preview with Toolbar and light theme.
Hope this helps.
I fixed this problem by switching to the Holo Dark theme, then back to the App theme. I just clicked the button above the viewer that says App theme next to the rotate view in Android Studio. About 10% of the time, that alone doesn't work and I also have to change the API of the viewer from 22 to 19.
No idea why this works, but the suggestions provided above did not work for me.
You don't need to change the theme. Maybe your're extending ActionBarActivity (deprecated) instead of just Activity. Change it, and build the project.
If you do change the activity from ActionBarActivity to just Activity, don't forget to import the Activity itself. That is
import android.app.Activity
It sucks but hey, it's their fault and not ours.
Also you can simply change the theme by pressing the "AppTheme" and choose Holo.Light.DarkActionBar. It updates the styles.xml file automatically.After that, rebuild the project.
I did all these and it works for me though i think them guys at Google and IntelliJ should do something about this rendering problem since we have been told to move from Eclipse to Android Studio
I recently updated Android Studio to version 1.2 and my AppCompat library to v22.0.0, SDK-Build-Tools version to 22.0.1. My target and compile sdk-version is 22 and my 'min-sdk-version' is 16.
The problem I am having is that in the xml-layout preview, I am getting an error namely: "Rendering Problems, the following classes cannot be found: android.support.v7.widget.Toolbar". I did some surfing on the internet and tried the already provided solutions. They are as follows:
Changing my (xml) preview to show android version target 21 or Android 5.0.1, 19, and 17
Changing my styles theme to Holo.NoActionBar and other themes as well.
Changing my minSdkVersion to 21 (above 20 basically)
Restarted Android Studio... Twice
Built the project about 5 times.
However, the problem still remains and I'm out of ideas. Could really use some help here. Thanks...
Also: The classes import just fine in my java file. It's just the preview.
EDIT: The preview works fine when I use android.widget.Toolbar. And my DrawerLayout doesn't work. I'm guessing there's something wrong with rendering the widgets from the support libraries?
I had a similar problem and you may want to try to change the app theme in the style.xml to an appcompat app theme for example with mine I changed it to something like this.
<style name="AppTheme" parent="#style/Theme.AppCompat.NoActionBar">
<item name="windowActionBar">false</item>
<!-- Customize your theme here. -->
</style>
and then go to the Android Manifests file
<application
android:theme="#style/whatever_you_named_your_app_theme">
In the Android Manifests file you write whatever you wrote in the styles.xml under <style name=""
There is no need to lower your apps targetSDK.
Give me feedback if it worked for you
I wiped out my entire project and started all over again. That seemed to solve the problem. I'm guessing changing my configurations in between is what caused the mess. Thank goodness the project was just for recreation.