I have an app where I haven't explicitly defined any colors. The app looks different on my phone than it does on a few other phones around my office (the title bar at the top of the app on my phone is blue with white letters and on other phones it's gray with white letters). How do I make them all the same? Is it as simple as just explicitly setting the color in my app?
You need to apply one of available themes to your application. You can do it AndroidManifest.xml, just use android:theme attribute:
android:theme="#android:style/Theme.Holo" if you want dark theme or android:theme="#android:style/Theme.Holo.Light" if you want light theme.
If you use put this app in one of your <activity> tags, only corresponding activity will be styled, if you put it in <application> tag, style will be applied to the whole application.
Of course, you can define your own style in styles.xml:
<style name="AppTheme" parent="android:Theme.Light">
<item name="android:windowBackground">#drawable/bg_window</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
Here's the example of AndroidManifest.xml:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name=".Activity1"
android:theme="#style/AppTheme2"
/>
<activity
android:name=".Activity2"
/>
In this example, AppTheme2 will be applied only to Activity1, while AppTheme will be applied to all other activities.
All the buttons, textviews and other UI elements not designed by you will change their aspect depending on the selected Theme. If you choose the default theme, all the GUI widgets will look different depending on the device manufacturer, the Android version, etc.
You can specify a concrete theme, such as Holo, with the problem that it won't work on Android versions prior to 3.0. You can keep the default theme for the old version, or otherwise you can use this website to generate all the Holo-style GUI elements yourself:
http://android-holo-colors.com/
the title bar at the top of the app on my phone is blue with white
letters and on other phones it's gray with white letters
This is the problem with the customized frameworks of some OEMs. They override the default android styles. I assume that the device with a blue title bar is a Samsung device with TouchWiz on it, right?
I order to have a consistent title bar you'll have to declare your own theme:
<style name="AppTheme" parent="android:Theme.Light">
<item name="android:windowBackground">#drawable/title_bar</item>
<item name="android:windowTitleStyle">#style/WindowTitle</item>
</style>
<style name="WindowTitle">
<item name="android:singleLine">true</item>
<item name="android:textAppearance">#style/TextAppearance.WindowTitle</item>
<item name="android:shadowColor">#BB000000</item>
<item name="android:shadowRadius">2.75</item>
</style>
The original title_bar 9 patch.
This is the answer to your question. However in my opinion you should't use title bars, use the ActionBar instead. You can use ActionBarSherlock for backwards compatibility.
Related
I have created a PreferenceActivity and set up a style for it in style.xml, both the regular and the v21 version of the file. The color scheme is default but in the style I changed the accent color to orange...this works great on the AndroidStudio emulator.
However, when I install the apk on my phone (Galaxy s6) the orange color is not used and in general the whole layout looks different than the default layout on the emulator before I changed the accent color to orange.
Why is this? Is there something I need to change so that the style/theme I customized on Android Studio applies to devices as well?
My style:
<style name="PreferenceTheme">
<!-- Customize your theme here. -->
<item name="android:colorAccent">#color/laborswipe_orange</item>
<item name="android:textColorHighlight">#color/laborswipe_orange</item>
</style>
My PreferenceActivity in the AndroidManifest:
<activity
android:name=".ProfileActivity"
android:label="#string/title_activity_profile"
android:theme="#style/PreferenceTheme"></activity>
Thanks in advance for the help!
PreferenceTheme has no parent. Also check if you override colors as expected inside this tag. Try this in styles.xml:
<style name="PreferenceTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="android:colorAccent">#color/laborswipe_orange</item>
<item name="android:textColorHighlight">#color/laborswipe_orange</item>
</style>
Also check if ide is connected to emulator on Run and doesn't hang on "Waiting for device to come online". In that case - check if Android versions match in Grandle Script build.gradle for minSdkVersion and targetSdkVersion and for emulator device. Check if theme is supported by these versions.
My base theme file for application is following wherein i am setting the primary colors and the accent colors
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/primary_yellow</item>
<item name="colorPrimaryDark">#color/primary_yellow_dark</item>
<item name="colorAccent">#color/accent</item>
<item name="colorButtonNormal">#color/primary_orange</item>
</style>
However when i am using the editext and switches as well as the radio buttons i am getting the stock blue color for the widgets when it is pressed or when it's state has changed.All i want is to change to the primary color which is set in my styles.xml.Also as i am targeting devices greater than API16,i want uniform support across all devices upto API22
Any help would be appreciated!
EDIT
Using the themes for entire aplication like this
<application
android:allowBackup="true"
android:icon="#drawable/launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
tools:replace="android:theme,android:icon">
Found the solution i created two styles.xml files one for API21 and above and one for API16 and above.In that added added these two lines to the base theme
<!--used for changing the focius colors of editext-->
<item name="colorControlActivated">#color/primary_yellow</item>
<item name="colorControlHighlight">#color/primary_yellow</item>
I have a custom view on an activity that is showed as a dialog.
I applied a custom theme to my activity so its parent is: "#android:style/Theme.Dialog" and I changed the window background to be transparent.
My Manifest.xml:
<activity android:name="com.rev.revcorder.ui.UserAuthenticationDialogActivity" android:screenOrientation="portrait"
android:theme="#style/userAuthenticationDialog">
</activity>
My styles.xml:
<style name="userAuthenticationDialog" parent="#android:style/Theme.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
</style>
The issue is that it is working fine on my device (Nexus 4 running 4.4) but on other device that is the same as mine (Nexus 4 running 4.4) it is not. Instead, the background is shown in black not transparent.
It only worked when I set it grammatically by adding:
getWindow().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00000000")));
My question is, what is the difference between setting the window background on my xml style and doing i grammatically ?
Also, how come it is working on my device and not on another same device ?
Thanks for your help
Add 2 more attributes to style like below code:
<style name="userAuthenticationDialog" parent="#android:style/Theme.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowIsTranslucent">true</item>
</style>
You can make a Custom Theme for all the devices.
For example, here is the declaration for a custom theme which is simply the standard platforms default light theme. It would go in an XML file under res/values (typically res/values/styles.xml):
<style name="LightThemeSelector" parent="android:Theme.Light">
...
</style>
To have this theme use the newer holographic theme when the application is running on Android 3.0 (API Level 11) or higher, you can place an alternative declaration for the theme in an XML file in res/values-v11, but make the parent theme the holographic theme:
<style name="LightThemeSelector" parent="android:Theme.Holo.Light">
...
Now use this theme like you would any other, and your application will automatically switch to the holographic theme if running on Android 3.0 or higher.
For more information about providing alternative resources, such as themes and layouts, based on the platform version or other device configurations, see the Providing Resources document.
Show below image how can u structure resources.
Update:
Also try this, set below Theme into manifest.xml
android:theme="#android:style/Theme.Translucent.NoTitleBar"
I used Theme.Sherlock.Light.DarkActionBar for my whole Application. Now the Action bar background color is black by default. How to change this color. Basically how to customize the Theme for whole Application?
<activity
android:name="com.mypath.myapp.FirstActivity"
android:label="#string/app_name"
android:theme="#style/Theme.Sherlock.Light.DarkActionBar"
>
You can use android:theme=theme_style in your <application> tag. Now if you want your action bar to be different than that given by the theme, then you can override it by defining the style between <style></style for your action bar specifically.
Here's the concept. Go to res > values > styles.xml. You can extend or customize your themes as follows:
<style name="AppBaseTheme" parent="android:Theme.Light">
<item name="android:background">#color/background_dark</item>
</style>
Update:
OR if you want to make generic (not theme specific) changes for all your applications, then you can edit sdk/platforms/android-target/data/res/values/styles.xml
OR if you want to override default themes for all your applications, then you can edit sdk/platforms/android-target/data/res/values/themes.xml
Update - found this:
ActionBar developer docs. This link says "You can control the behaviors and visibility of the action bar with the ActionBar APIs, which were added in Android 3.0 (API level 11)." So I assume your target is API 11 at minimum.
If you are targeting API 11 and above, you can do advanced custom styling as follows:
<resources>
<style name="CustomActivityTheme" parent="#android:style/Theme.Holo">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#drawable/ab_background</item>
<item name="android:backgroundStacked">#drawable/ab_background</item>
<item name="android:backgroundSplit">#drawable/ab_split_background</item>
</style>
</resources>
Here you go , Styling Action Bar background
You can define the theme for your whole application in your manifest file in application tag as below:
<application
android:name="com.test"
android:icon="#drawable/appicon"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar" > <---Define your own style here.
Have a look at http://actionbarsherlock.com/theming.html . You must create a own Theme-style.
for modifying default android sdk themes You can find android Sdk themes.xml file in :
\android-sdk\platforms\...\data\res\values\themes.Xml
so you can change your whole application theme.
Each "layout" I set a white background and "Manifest" I set Theme.Light.
Still receives a gray background instead of white. Why?
Edit:
Manifest.xml
android:theme="#android:style/Theme.Light.NoTitleBar">
Layout
android:background="#android:color/white"
Theme.Light does not mean that it will be white. It just means that it will be light, not dark :P This is not theme.white.
Each device manufacturer can customize Android OS on his phone for example to preferred colors and look & feel. In particular he can define styles for his Android implementation - Light and dark. Thanks to that your app may look differently on various devices, however it will always fit the style used on this device (every app in style Theme.Light will have grey background on this device, unless you set android:background="#android:color/white" )
Your device's manufacturer defined style Theme.Light as style with grey background.
Hope that I am clear - otherwise do not hesitate to ask
I had the same issue until I changed #android:color/white to explicit android:background="#FFFFFF". Weird though...
Since it's an old question this might have another solution already but anyway one can just enter the AppTheme style tag in styles.xml, you can do so by pressing the ⌘cmd key and clicking on your theme declaration in the manifest.
Over there add this line with your preferred color -
<item name="android:windowBackground">#color/white</item>
This line basically overrides the theme's default background value.
Example -
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:colorControlActivated">#color/black</item>
<item name="android:windowBackground">#color/white</item>
</style>