I've taken the basic Hello World app from the SDK examples and have been learning Android by modifying it. Currently I'm trying to change the Theme. I'm testing it on my Nexus 7 running the latest OS and I'm using Eclipse.
In my manifest I have
android:theme="#style/AppBaseTheme"
In values-v11/styles I have
style name="AppBaseTheme" parent="android:Theme.Black
I've tried using Holo and am aware I need to be V11 or higher to do that.
When I try running my app it starts on the tablet and I can see the black background as expected, but before it can draw any components Eclipse goes to debug mode in ActivityThread.performLaunchActivity and then into ZygoteInit$MethodAndArgsCaller.run() before my app dies.
If I use this it's fine:
style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light"
I feel I'm missing something obvious or there's a fundamental part of Themes that I don't understand. I have tried removing the .android/ directory and restarting Eclipse, that fixed a few other issues.
I know the # symbol in this context denotes that it is an inbuilt style by android. Does that mean I have to add something to my app to link in other themes? If so what exactly?
Related
I'm trying to change the theme of an app that I'm trying to develop using Android Studio. Apparently, there are at least two ways to do so: by editing the styles.xml file and by using the button above the preview (for me it's the middle button stating the name of the selected theme).
What I'm witnessing is this: When I try to change the theme by using the button, it will update the preview. When I edit the styles.xml file, neither the button caption nor the preview change. And when I run the application, neither the theme chosen using the button nor the theme specified in the styles.xml file are used.
So for example, I have chosen "Material Dark" using the button and specified Holo Light in styles.xml like so without the two interfering with each other at all:
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
And then, when I finally run the app in an emulator, I don't even know the theme (light gray action bar, black text color) that it displays the app in but it's not one that I have specified.
That being said, (almost) every other change I apply to the app in any way using Android Studio is displayed just fine both in the preview and in the emulator. An exception to that rule is the changing of the text color of the elements through the activity's XML file...
I'd appreciate any help, since I'm at my wit's end and also somewhat new to the whole thing.
Thanks! - koala
This is because ide sees no emulator. Emulator always run, but ide could hang up in state "Waiting for target device to come online".
Possible reason - Android API versions mismatch. Check if minSdkVersion and targetSdkVersion in Gradle Scripts - build.gradle (Module: app) correspond device API (also Synch push Synch Project with Gradle Files on a panel). Also low versions (e.g. API 15) result in ide-emulator link failure, inspite of application and device versions match.
Reading the Compatibility section of Android L Developer Preview (http://developer.android.com/preview/material/compatibility.html) I've seen that i can create an APP using L-sdk and also be able to run it on older sdk (like KitKat).
I've created a new project using Android L sdk and configured "build.gradle" as said in this post: Android Studio : Failure [INSTALL_FAILED_OLDER_SDK].
I've tried both the configurations:
the one proposed in question that gives me this error:
pkg: /data/local/tmp/com.example.{my user name}.materialapp
Failure [INSTALL_FAILED_OLDER_SDK]
and the one proposed in answer that gives me error on
<style name="AppTheme" parent="android:Theme.Material.Light"></style>
I've searched on others question on StackOverflow but I can't find no solutions.
SOLUTION:
Android L preview material style can be used only on devices that run Android L.
The "compatibility" is only a preview and it's not enabled.
You have to create 2 different styles.xml files with the same name that you will put in different folders.
The first, will go here:
res/styles.xml
and will look NOT have a reference to the Material theme (use the Holo theme):
so would have something like this:
<style name="AppTheme" parent="android:Theme.Holo.Light"></style>
The second will go here:
res/values-v21/styles.xml
and WILL contain the reference to the new Material theme, and would have:
<style name="AppTheme" parent="android:Theme.Material.Light"></style>
The Android framework will automatically use the correct one depending on which API the device supports (so on API 21 devices it will use Material, and on all other devices, it will use whatever else you define).
This has changed since the original answer, as Google released better support for Material design in the AppCompat libraries (which support mostly all versions of Android).
At this point, you should be using these libraries for all development, then you will be able to support Material design related features in all your apps.
Here is how to set it up: https://developer.android.com/topic/libraries/support-library/setup.html
I'm trying to style my application with custom styles. However, I am facing a problem when on install of application the styles aren't applied, then if I change something (anything) in the styles and compile it again (reinstall not uninstall followed by install) it applies all the styles. But as you understand this isn't an intended experience for users.
What could cause such a strange behavior?
UDATE:
The api is from 13 to 17.
I'm getting this:
Instead of this:
As you can see the styles aren't applied to this dialog. This also happens to other activities.
I am using Eclipse ADT to develop my first Android application.
In Eclipse you can change the theme using the menu shown in the Graphical Layout window. I decided to use the Black theme because I like the way the UI components look using that theme.
One of my UI widgets is a seek bar. Here is how it looks using the Black theme:
When I test (run) my application using the Nexus S virtual device the seek bar looks different:
Why do they look different? (I am guessing that Eclipse is just showing me a preview of what that theme would look like and not actually setting it anywhere and that when I run my app it inherits the theme from the target platform.) Is there a way I can force the look and feel of my app?
Thank you.
Because the Android UI has evolved and changed. The first image you posted is Android 2.2 (ish) and then the second image looks like Android >= 4.0.
Secondly, AFAIK, changing the theme from that menu is ONLY for checking out the apps UI within the GUI layout editor - it will not change the theme on launch within the emulator, or a real device. For that you need to specify the theme within your manifest.
You can change the version of Android being used in the preview too, using the Android icon on the far right of the GUI editor. You can also preview more than one at a time using the far left icon on the same toolbar.
What Rawkode said.
I'll add my two cents:
You can take a look at the HoloEverywhere project if you want to have a consistantly looking application across all Android versions.
The project is essentially a backport of the Holo theme for Android pre 4.0.
You can check it out here:
http://www.holoeverywhere.com/
I wanted to use Theme.Wallpaper in my app. This theme uses the phones current wallpaper as a background. The problem is it doesn't work on a 4.1 device. I also tried recreating the Theme.Wallpaper in my style resources but again it doesn't work for 4.1 devices.
- note that it may not work for lower APIs as well, I only confirmed it working on 2.2.1 and not working on 4.1.
I would like to know why it doesn't work and if there is any solution to that.
I have finally found the answer, it's a bit complex:
In a project built for a target above 14 (mine is 17) eclipse automatically creates a "values-v11" and a "values-v14" folders (applyed for phones or AVDs with api version 14 and above or 11 and above). In those folders are style.xml files that contain the "AppBaseTheme" style, This "AppBaseTheme" style replaces the one in the default "values" folder, which is the parent of (or: is extended by) the "AppTheme" style that is applyed by default to the application..
Now, the way I chose to apply the "Theme.Wallpaper" style to my app, was to have my "AppBaseTheme" inherit from it. Understanding this, it became obvious why my app did not have a "Theme.Wallpaper" like behavior on Systems with API 11 and above: I never made the alternative v11 and v14 "AppBaseTheme" extend the "Theme.Wallpaper" or the more suitable "Theme.Holo.Wallpaper" for v11, and "Theme.DeviceDefault.Wallpaper" for v14.
So, if you have troubles with applying styles, I hope you see this...
EDIT: if your reading this, and have troubles with editing the style.xml file in eclipse, try opening this file in any text editor (my favorite is notepad++) and just delete all the comments than reopen it on eclipse. In case you need comments just add them afterwords on your text editor.