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"
...>
Related
When the Cordova android app launches, a blank screen is briefly visible before cordova-plugin-splashscreen kicks in. I have learned that this is the windowBackground colour and can be changed by making a custom styles.xml and referencing it within AndroidManifest.xml though the activity's android:theme property. Example:
From AndroidManifest.xml:
<activity android:configChanges="orientation|keyboard|keyboardHidden|screenLayout|screenSize" android:label="#string/activity_name" android:launchMode="singleTask" android:name="MainActivity" android:screenOrientation="portrait" android:theme="#style/CustomStyle" android:windowSoftInputMode="adjustPan">
From styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomStyle" parent="#android:style/Theme.Material.Light.NoActionBar">
<item name="android:windowBackground">#drawable/init_splash</item>
</style>
</resources>
styles.xml references another file just containing a drawable colour.
This works. It allows me to change the colour that appears before the splash screen.
However, I am now looking to allow the user to optionally change to a dark theme. I have already figured out how to modify cordova-plugin-splashscreen to change the splashscreen based on the user preference, but I'm having trouble changing the windowBackground/theme programatically at runtime.
I have tried adding the following within MainActivity.java or CordovaActivity.java:
setTheme(R.style.CustomDarkStyle);
getWindow().setBackgroundDrawableResource(getResources().getIdentifier("init_splash_dark", "drawable", getPackageName()));
getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK));
I placed these in the onCreate before super.onCreate() or setContentView(). The window background colour does indeed change, but the initial blank screen before the splash stays at whatever colour was set in the manifest.
How can I change the activity/window background colour programmatically when the application is started?
Some have suggested changing the app theme to a transparent one to prevent the blank screen entirely, but that causes a delay in opening the app. I'm fine with the blank screen, I just want to change it's colour programmatically.
As of April 22nd, I am yet to find a solution to this problem.
Create a class with the same name as of your project and it will extend Application not Activity. Put this code inside this class as this will be automatically initialized as soon as your application starts. It will be acting as a constructor for your application.
Hope it helps!
I have a project named "slot" so i created a class named slot like this
package com.xyz.slot;
import android.app.Application;
public class slot extends Application {
#Override
public void onCreate() {
setTheme(R.style.CustomDarkStyle);
super.onCreate();
}
}
But make sure there is no theme set in manifest as it will not be overridden.
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"
/>
I have tried both Theme.DeviceDefault and Theme.Black in my styles.xml, and both make my 2.1 emulator become black correctly, but on the 4.1 emulator it stays white...am I doing something wrong?
<resources>
<style name="AppTheme" parent="android:Theme.Black" />
</resources>
PS: I presume the drop-down for "Theme" at the top of the Graphical Layout is just showing me what it would look like, it's not some kind of setting that's going somewhere (for the app)?
The Android system always chooses the most special values folder that fits best to your device.
As example if you have a folder values and another folder values-v14 the Android system takes resources from the latter if the device is v14 or newer.
Please refer to the Android documentation for more information.
1.create new folder under res -> values-v13
2.create file style there and add this style :
<style name="AppTheme" parent="android:style/Theme.Holo.Light">
in your manifast use this style for your application like this
<application
android:name=".MainApp"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
that way on ICS version you use the Holo.light theme and pre ICS use the default you already created
Setting it via styles doesn't actually work, but if you set it explicitly for application it works.
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black" >
By default 4.0 and 4.1 give us white background but you can change it to black I face the same problem some days ago, if your project theme is set to be black then probably you change the Title while creating project to "Main" by default its "MainActivity" but if you change it to "Main" it will give you black backgrount/
I don't know my answer is relevant to your question or not but i think you talking about this if i am not wrong.
Currently my android has black background and white foreground(text color), I want to change it to some other theme, is there any market available that I can download theme xml files that can be used in my app?
You don't have to download the light theme in order to use it. It comes with the system. You just need to indicate in your manifest that you'd like your activity to be shown with the light theme. Here is an example:
<activity android:name="NoteEditor"
android:theme="#android:style/Theme.Light"
>
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">