Can I set a theme for the app I create?
I am talking about themes like in...
http://developer.android.com/design/style/themes.html
or should I use Styles and themes, and individually modify every child?
You indeed have to use Styles and Themes.
You can add a theme to whole of your application with just one line in the manifest:
<application android:theme="#style/CustomTheme">
Related
I am making an app, that has a lot of text to read, and i want it to have 2 themes. dark and light. So i think the way to do this is to have 2 XML layouts. But I don't know how to set a 1 style to 1 laayout, and a different style to a different layout. There is a field android:theme in the manifest, but that sets a theme to the whole app, and not a specific layout.
So, to be clear, my question is; How do you set a style/theme to a specific activity and not the whole app?
In the manifest, android:theme can be added to the activity tags, and those override the application tag theme.
<application
android:theme="..." <!-- App theme -->
...
<activity
android:theme="..." <!-- Theme for just this Acitivty -->
You can also try to programmatically call setTheme in an Activity class
i think the way to do this is to have 2 XML layouts
You just need one layout that can pick up the attributes of the theme(s) you'll set
I have an Android app that has a default theme of Holo.Light but I want to change it to Theme.Black.I tried to do this by changing the style tag in the manifest android:theme="#style/AppTheme" to Theme.Black but it cannot be found.Is there extra steps I have to take in changing the theme?
Actually you should define your styles in res/values/styles.xml. I guess now you've got the following configuration:
<style name="AppBaseTheme" parent="android:Theme.Holo.Light"/>
<style name="AppTheme" parent="AppBaseTheme"/>
so if you want to use Theme.Black then change AppBaseTheme parent to android:Theme.Black or you could change app style directly in manifest file like this - android:theme="#android:style/Theme.Black". You must be lacking android namespace before style tag.
You can read more about styles and themes here.
To change your application to a different built-in theme, just add this line under application tag in your app's manifest.xml file.
Example:
<application
android:theme="#android:style/Theme.Holo"/>
<application
android:theme="#android:style/Theme.Holo.Light"/>
<application
android:theme="#android:style/Theme.Black"/>
<application
android:theme="#android:style/Theme.DeviceDefault"/>
If you set style to DeviceDefault it will require min SDK version 14, but if you won't add a style, it will set to the device default anyway.
<uses-sdk
android:minSdkVersion="14"/>
If you are trying to reference an android style, you need to put "android:" in there
android:theme="#android:style/Theme.Black"
If that doesn't solve it, you may need to edit your question with the full manifest file, so we can see more details
Or try to check your mainActivity.xml you make sure that this one
xmlns:app="http://schemas.android.com/apk/res-auto"hereis included
When an app does not set the theme itself, it will call the system default theme.
Now the android default theme is black background and white text. I want to set the default theme due to my wish.
Who knows where can set the default theme in android project?
The android manifest.xml has the attribut android:theme="resource or theme". This attribut sets it to holo dark or light or your own declared theme. To use your own layout you msut declare and build your own layout in the res/values folder.
Here's the documentation about it: http://developer.android.com/guide/topics/manifest/application-element.html
In menifest.xml file you can set default theme like
<application
android:theme="#android:style/Theme.Black"
/>
Why is there a difference between theme defined in AndroidManifest.xml and theme taken from styles.xml?
1) AndroidManifest.xml:
<application ... android:theme="#android:style/Theme.Black">
2) AndroidManifest.xml
<application ... android:theme="#style/AppTheme">
styles.xml
<resources>
<style name="AppTheme" parent="#android:style/Theme.Black" />
</resources>
1st setting gives black theme and no action bar. 2nd has dark action bar and light menu.
EDIT : options 1) and 2) - notice Menu and ActionBar
EDIT 2:
Why doesn't the 2nd option actually use the AppTheme (Theme.Black) ? (tested on SGS3)
You probably have another styles.xml file, perhaps under a directory like "values-v11", that is defining the #style/AppTheme differently than #android:style/Theme.Black and taking precedence over the file you're viewing/modifying.
#android:style/Theme.Black implements the exact theme implemented by Android (or device manufacturer). However, #style/AppTheme allows you to perform custom modification in your theme which actually extends the original Theme.Black from android, and in order to perform custom modifications, you use style resources.
In simple words, its just like using Activity class or YourOwnActivity class which extends Activity with extra features inside.
Styles.xml enables you to create your own themes. In AndroidManifest, you set the theme you want for an app or activity. You may want to use a system theme or your own. You can also extend other themes as you're doing setting "parent" attribute. For further information, check this out:
http://developer.android.com/guide/topics/ui/themes.html
You should try to put:
<resources>
<style name="AppTheme" parent="#android:style/Theme.Black" />
</resources>
in a xml file called res/themes.xml
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">