I'm quite new to android dev and would like to know, how can I choose the current theme of the phone. I'm developing on the Galaxy Tab and the current theme is a nice white one (if I go into the settings menu for example). But the default theme in the sdk seems to be Android.Black.
I would prefer not to hardcode any choice and let the app use whichever one is chosen on the phone/tab...
I'm not sure exactly what your question is aimed at, so I'll answer in two parts:
How do I let the app choose the current theme on Android?
The theme is set automatically (by default) to be whatever system theme the current device/user has selected. If no style or nested theme attributes are defined, then your app will be set to reflect the system style. For instance, if the default font color for the theme is #AFAFAF, the default font color for your app will also be #AFAFAF, unless otherwise specified by a style or theme resource.
If I don't like the current theme, how do I set my own theme?
You mentioned that you liked the nice white theme on the Galaxy tab. You are correct in that different versions of android use different system themes including fonts and backgrounds.
To get the current theme (to decide if it's the one you want), simply use the getApplication().getTheme(). If it's the theme you want, you don't have to do anything. If you want to apply logic and programatically set the theme, use the getApplication().setTheme([theme]) method to change it.
You can also specify both application-wide themes and themes for individual activities and you AndroidManifest.xml file as follows:
//for themes defined in res/values/style.xml
<application android:theme="#style/myApplicationTheme">
<activity android:theme="#style/myApplicationTheme">
//for system themes
<application android:theme="#android:style/Theme.Light">
<activity android:theme="#android:style/Theme.Light">
And, as always, to individual view elements.
If you're looking to implement a specific system theme, be sure to check out the complete theme specifications. These will list all system themes as well as all defined style elements for each of the themes so you can use the desired theme or make your own variant.
If you're particularly fond of the light system theme, it can be set for your application using
<application android:theme="#android:style/Theme.Light">
Related
I've added dark theme support for my application using 2 different themes declared in styles.xml.
On official android developer site:
In order to support Dark theme, you must set your app's theme (usually
found in res/values/styles.xml) to inherit from a DayNight theme
and this is what I've done. I've also created colors-night.xml to avoid modifying colors that cannot be modified in styles.xml by coding and this works too: when dark mode is activated from device system, colors changes automatically.
At this point, I was wondering which is the best way to implements dark theme: creating 2 different themes, using colors-night (and drawable-night) or a combination of these 2 ways?
First up is the youtube video below pretty much tells you what the current best practices are with regards to theming.
https://www.youtube.com/watch?v=Owkf8DhAOSo
They talked about splitting your styles into
themes.xml -> theme related styles
styles.xml -> component related styles
type.xml -> text appearances styles
All your colors should then be in one colors.xml which lives in values.
You will then have the following structure:
values/themes.xml
values/colors.xml
values/type.xml
values/styles.xml
values-night/themes.xml
In practice, I find that it is still hard to contain all the colors in just one colors.xml. I still create values-night/colors.xml as some colors don't necessarily fall into a style.
See this in practice in this repo. Observer that Google themselves didn't follow their point on just using one colors.xml.
https://github.com/material-components/material-components-android/tree/master/material-theme-builder
I have been developing an Android app for quite some time now and almost everything is how it's supposed to be. However, I'm having some issues with themes for some views. My application uses a AppCompat.Light based theme as shown bellow:
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar"></style>
Everything looks white and clean, but I have one specific screen that is kind dark. So I created the following theme for some EditText fields:
<style name="InputField" parent="Theme.AppCompat"></style>
in order to make the input fields have white colors. I then run the application on devices with different Android versions. On a smartphone with Android 5.0.2, everything looks as I expected. On a smartphone with android 4.4.4, however, the input is dark. I even tried to change the theme of the input field theme to
<style name="InputField" parent="Theme.Holo"></style>
or
<style name="InputField" parent="#android:style/Widget.Holo.EditText"></style>
in the values-v19 styles, but it still looks dark. If I change the application theme to
<style name="AppBaseTheme" parent="Theme.AppCompat.NoActionBar"></style>
the input fields look as they should, but the entire rest of the app is dark themed and it's not what I want. I can only assume that application theme is having some influence over my views theme, even though I explicitly specified the theme they should use. The same behavior happens on a smartphone with android 4.2.2.
System provided styles doesn't define used colors, they have only references to a theme attributes. Colors are defined the theme, thus, it not enough, if you set parent to some system style.
Starting API 21 (5.0) you can override theme for specific views (or styles) by setting attribute android:theme. For older versions you will need to define specific colors and drawables in your style.
Can anyone tell me how I can change my apps theme from the default ones made available? Holo and Holo.Light get a bit boring after a while.
The likes of Facebook, Google+, BBC Weather, Viber, Vine and Twitter all look very professional and have their own theme whereas the app I'm developing looks quite boring.
Is it possible to change the font of the text in my app? I know it's possible to change the colour and size of it.
Another thing which would be useful to know would be how to change the colour of the action bar that is used for my app. Currently it's black but I wouldn't mind changing it to a different colour than those used by the Android default themes (e.g. purple, green, blue, etc)
Maybe you can share some tips on what you think works well for Android design?
You can generate a custom theme at http://jgilfelt.github.io/android-actionbarstylegenerator/
If you only want to change a few font an colors etc take a closer look at this (source:http://developer.android.com/guide/topics/ui/themes.html)
If you like a theme, but want to tweak it, just add the theme as the parent of your custom theme. For example, you can modify the traditional light theme to use your own color like this:
<color name="custom_theme_color">#b0b0ff</color>
<style name="CustomTheme" parent="android:Theme.Light">
<item name="android:windowBackground">#color/custom_theme_color</item>
<item name="android:colorBackground">#color/custom_theme_color</item>
</style>
(Note that the color needs to supplied as a separate resource here because the android:windowBackground attribute only supports a reference to another resource; unlike android:colorBackground, it can not be given a color literal.)
Now use CustomTheme instead of Theme.Light inside the Android Manifest:
<activity android:theme="#style/CustomTheme">
I'm wondering why, every time I create a new Android project, Eclipse opens a main activity with a white background, when in previous versions, it was black.
Is there any way for me to change that back to black as a default color for future activities?.
They changed the default theme that eclipse uses in your resources to the light theme. Change your resource files (delete the stuff eclipse added that you don't use) and it will go back to black.
So if you want to reskin your whole application to black, you can use following line in your manifest file.
Write to Application tag attribute theme.
<Application
android:theme="#android:style/Theme.Black" //old targeted application
OR
android:theme="#android:style/Theme.Holo" //for new devices
... >
Now all activities in this application have black theme.
You can "override" this by using theme attribute in Activity tag.
<Activity
android:theme="some theme"
...>
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.