I'm using the HoloEverywhere library in my Android app to ensure a consistent theme across all supported devices. However, I'm running into trouble with activities that utilize Holo.Theme.Dialog: on my Android 2.2 emulator it displays correctly, but on my Android 4 device (which has the actual Holo theme available) the layout cuts off items on the right edge of the dialog.
My question is, how can I force devices that have the stock Holo theme to use that instead of HoleEverywhere? Or, how can I modify HoloEverywhere to make activities styled as dialogs display correctly on Android 4+ devices?
Screenshots:
Dialog in Android 4+
Dialog in Android 2.2
I'm not sure if this bug has been fixed in HoloEverywhere or not, but my solution was to change all of my dialog activity classes to AlertDialogs. This required some code changes, but now I can be sure my dialogs will look and act as expected.
Here's what you need to do:
In your values folder, create a style in styles.xml file referencing Holo.Theme as a parent. In my case, I used AppBaseTheme
<style name="AppBaseTheme" parent="Holo.Theme.Light"></style>
In your manifest, make sure that you are referencing this style in your activities and in your application tag.
<application
...
android:theme="#style/AppBaseTheme" >
Create a folder in your res folder named values-11 (if there isn't one already)
Create another styles.xml file.
Copy the same style you placed earlier in values folder, but reference the built in Holo theme included in 4.0
<style name="AppBaseTheme" parent="android:Theme.Holo.Light"></style>
Related
In my android studio, there is no style.xml file.
There is a themes folder having two themes.xml files.
Please tell which themes.xml file should we use for android tab functionality.
It got changed in Android studio 4.1
Actually, in the older versions of Android studio, if you want to enable dark mode in your app, you have to manually create and define the properties in your dark theme XML file, but now it is automatically generated as mostly all new apps are moving towards dark mode in their applications.
You can still delete these files from your Android studio project if it doesn't fit in your use-case.
There are two themes.xml in the new Android Studio project templates.
One is for a light theme and the other one is for a dark theme.
More info on dark theme
Implementing a dark theme (or black theme) is very easy today thanks to
Theme.DayNight and
AppCompatDelegate
Android comes to us allowing us to declare
night/colors.xml
and
night/styles.xml
Full example here: https://github.com/android/user-interface-samples/tree/master/DarkTheme
In my current project, when I select the Design tab in Android Studio 2.2.2 for a particular layout I get an error that says
Missing styles. Is the correct theme chosen for this layout?
and it goes on to say
Failed to find style 'textEditSuggestionItemLayout' in current theme
(42 similar errors not shown)
But, the actual layout renders OK in the Designer and at runtime.
There are lots of other S.O. posts on this, such as here and here and most of the answers seem to involve clearing the caches and restarting Android Studio, or selecting a different theme from the dropdown. I I have tried the first one but it didn't help. I haven't tried the second one yet because I don't really understand what a theme is.
Questions:
The error implies that there's an error in the theme itself. What
is that? Is the theme file part of my project, i.e., is it one
that I should be creating, editing, and that gets built and shipped
as part of my APK or is it only used in the developer IDE?
If I select a different theme from the dropdown how do I know what the
"correct" one is?
Since my project builds and runs OK as is, can I just ignore these
errors? In other words are these errors in my code or just a
problem with the development environment?
Edit: Some additional information after responding to comments, below:
The only place the string 'theme' is used in my manifest is
android:theme="#style/Theme.FullScreen"
... and FullScreen is the theme specified in the dropdown.
I did a search in my project for the string "textEditSuggestionItemLayout" and Android Studio found no occurrences of it.
If you've recently updated AS or any of its components, then try to 'Invalidate caches & restart'.
Else, try choosing AppTheme from the Design tab or change it to AppTheme from the default one. Choose the one that conforms to your parent app theme in your styles.xml.
The cause of the error could be anything from malfunctioning IDE to selecting a theme not mentioned in your styles.xml (most likely).
You could do a project-wide search for textEditSuggestionItemlayout, or the other styles that it claims to miss.
These are either in your own res/values/styles.xml and/or res/values/themes.xml files, or they are provided within the SDK, which is why you see some suggestions to uncheck 'Automatically Pick Best' and pick a version you have installed. In some cases, the latest API version's rendering tools don't work.
As an example, if you have your style set at Theme.Holo, but you are using the AppCompatActivity, you'll get a rendering error that you must use a Theme.AppCompat (or descendant). These themes are changeable from the dropdown of the design editor.
You can see what themes/styles are applied to your Activities within the AndroidManifest.xml.
res/values/styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/PrimaryColor</item>
<item name="colorPrimaryDark">#color/PrimaryDarkColor</item>
<!-- Customize your theme here. -->
</style>
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
Note: android:theme= and #style/
If you are still missing themes, then you may be missing some dependency, such as
compile 'com.android.support:design:<your_version_here>'
If your code runs fine, then sure, ignore it, but I think getting the layout designer working again shouldn't be ignored.
I have a couple of app that were created with Android 1.6 and after. The problem is when I run these app on recent Android (device or simulator) like ICS, I don't have the Holo theme.
I know i can find a lot of thread on how to specify the theme but when I create a new app now, I have the new theme without any lines of code.
I don't want to have ICS theme on all android version, just ICS theme on ICS, like new holo buttons style on ICS and old grey style for older. Now I just have grey buttons for all versions.
I can create new empty projects and copy all my files into it but there must be a hidden value somewhere to chenge this.
In my manifest I have:
<uses-sdk android:minSdkVersion="3" />
<uses-sdk android:targetSdkVersion="14" />
What can be the difference between old and new created projects ?
What I'm understanding is that you want your app to switch between the legacy (classic) theme and the new Holo theme based on API version.
First, in your values (res/values) folder make a new xml. Call it styles.xml. It should contain these lines:
<resources>
<style name="AppTheme" parent="#android:style/Theme.Black"/>
</resources>
Then make a new folder in res called values-v11. In this new folder make another new xml. Also name it styles.xml This file should contain these lines:
<resources>
<style name="AppTheme" parent="#android:style/Theme.Holo"/>
</resources>
Then in your AndroidManifest.xml you Application node should contain this line:
android:theme="#style/AppTheme"
Now on devices with Honeycomb or higher you get the Holo theme and for everything else, you get the old classic theme. You can easily experiment with this to suit your needs - this is the general way to switch between themes based on API version.
hi i have a question about the gui of a android application.
when i start a project and select 2.3.3 as my api version. i add some gui stuff like a button and then run the code on a 4.0.3 device.
the problem is now: the button looks like a 2.3.3 button and not like the 4.0.3 version.
is there any way to change this?
You have to use one of the Holo themes for API Level 11+:
Create res/values folder
Define your application theme like this:
<style name="AppTheme" parent="#android:style/Theme" />
Create res/values-v11 folder
Define your application theme like this:
<style name="AppTheme" parent="#android:style/Theme.Holo.Light" />
Use AppTheme in AndroidManifest.xml
For further reading, see section Using Holo while supporting Android 2.x in this article.
And if you want Holo for 2.3.3 applications I can recommend this project. Just follow the instructions on the site on how to use it.
I know how to set the theme for an Application and/or Activity in Android, but I'm wondering if it's possible to change it for an Activity using the Graphical Layout editor in Eclipse 4.2, ADT 20.0.1. No matter what I change the drop-down to, the AppTheme style from styles.xml is always used when I run the app, despite the display preview changing based on what I select. Is it currently not possible because the theme gets set in the AndroidManifest?
styles.xml:
<resources>
<style name="AppTheme" parent="android:Theme.Light" />
</resources>
The drop down box in the GUI is used to see what it looks like, if you want the theme changed then you have to edit the Android Manifest yourself
If you want to edit the theme using a drop down, in one of the tabs in the Android Manifest, I think its "Application" there is an option to change the theme and it has a list of themes.
Yep, the theme must be set in the Manifest or in Java.
The drop-down on the layout editor is only there to help debug and test theme issues and whatnot, it doesn't have any effect on your actual app.