How to customize the Theme for whole Application - android

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.

Related

Android: preview shows different styling - action bar

Just started learning developing android in android studio, and created a custom theme which needs to hide the action bar on a inheriting styling.
On runtime the theme actually does hides the action bar but the preview does not, which makes it a bit difficult creating a layout based on the preview.
I've probably done something wrong or just not understanding how to use theme's and stylings with the preview correctly.
The custom theme I've made
<style name="AppTheme" parent="Theme.AppCompat">
...
</style>
<style name="AppTheme.MainLayout">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
The intention is to use the .MainLayout styling on certain activities instead of the whole application.
How I'am applying the usage in manifest file
<application
...
android:theme="#style/AppTheme">
<activity android:name=".MainActivity"
android:theme="#style/AppTheme.MainLayout">
...
</activity>
</application>
As explained this does hides the action bar on runtime but doe'snt in the preview.
I also tested how the preview does behave on applying the style directly in the layout.xml file.
activity_main.xml
<RelativeLayout
...
android:theme="#style/AppTheme.MainLayout"
</RelativeLayout>
For testing purpose I've added an extra styling in the AppTheme.MainLayout
<item name="android:textColor">#color/colorPrimary</item>
Result
What I am observing on this is:
The preview doesn't hides the action bar but does apply other styling (like the text color) correctly.
To wrap this question up: why is the preview different on not hiding the action bar when using the .MainLayout, and how to fix this?
Thanks in advance.
Edit:
Preview 'settings'
In your Design layout manager try to select Theme (click AppTheme).
Try to change:
<style name="AppTheme" parent="Theme.AppCompat">
to:
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">

Can someone please help me understand why this code is not turning the Android Action Bar yellow?

I followed the Google's tutorial for changing the color of the Action Bar and wrote the code shown below, but the Action Bar still shows up as per the Holo Light theme.
styles.xml:
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat.Light">
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<!-- Support library compatibility -->
<item name="background">#color/yellow</item>
</style>
Android Manifest:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light" >
<activity
android:name="com.example.labside.MainActivity"
android:label="#string/app_name"
android:theme="#style/CustomActionBarTheme" >
The colors.xml has yellow defined as #FFFF00. Please let me know what I am doing wrong as this whole stuff about Action Bar styling with support for API level 8 is starting to get very confusing! As always, many thanks for all your help!! :)
What android version are you using? Take a look at this post: custom style action bar not working in android 4
Following this post, you need to declare your custom style twice. It looks like you are missing the declaration with the android: prefix.
So I guess, you'll have to add:
<item name="android:background">#color/yellow</item>

Change action bar logo on Gingerbread in xml

I'm trying to show a logo in my action bar that is different from my app icon in an app that needs to be compatible with 2.3 (Gingerbread). Right now I have,
android:icon="#drawable/icon"
android:logo="#drawable/logo"
in my manifest file which correctly shows on 4.0 and above devices. However, all of the action bars on 2.3 devices show the icon instead of the logo. The following code in onCreate in an activity works on 2.3 devices:
getSupportActionBar().setLogo(getResources().getDrawable(R.drawable.logo));
But, I'd like to avoid having to set this separately in each of my activities. Is there a way to set this in xml, in the manifest or theme perhaps? I've also tried
<item name="android:icon">#drawable/logo_listy</item>
in my theme actionBarStyle.
You can specify android:icon for each activity in the AndroidManifest.xml.
I'm using Google's ActionBarCompat for this; if you're using ActionBarSherlock the same thing might work, but I haven't tried it.
You can set a logo in the style you have applied to the action bar in your app's theme. For example:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle" tools:targetApi="11">#style/AppTheme.ActionBar</item>
<item name="actionBarStyle">#style/AppTheme.ActionBar</item>
</style>
<style name="AppTheme.ActionBar"
parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<!-- this can be set in the manifest or here, and will set the logo for -->
<!-- devices with API level >= 11 -->
<item name="android:logo" tools:targetApi="11">#drawable/logo</item>
<!-- this will set the logo for devices with API level < 11 -->
<item name="logo">#drawable/logo</item>
</style>

Simple Android app color

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.

Extending styles and themes confusion

In my manifest I used to have something like this
<activity android:name=".MyActivity"
android:label="#string/app_name"
name="Theme.NoTitleBar"...
and it worked great, I mean the title bar was not shown.
But now I want to customize the theme (I want to extend the default android theme)
and I created this theme
<style name="Theme.NoTitleBar.new_skin" parent="android:Theme">
<item name="text_body_read">#style/text_body_read</item>
<item name="text_body_unread">#style/text_body_unread</item>
</style>
then in the manifest I set name="Theme.NoTitleBar.new_skin", but the title bar is still shown.
how can I hide the title bar and still have my new custom theme ?
and one more question does adding dots '.' means extending when working with styles ?
in your mainfest you should write something like:
<activity android:name=".MyActivity"
android:label="#string/app_name"
name="MyTheme"...
In your styles.xml you should write something like:
<style name="MyTheme" parent="android:Theme.NoTitleBar">
<item name="text_body_read">#style/text_body_read</item>
<item name="text_body_unread">#style/text_body_unread</item>
</style>
Dot (.) doesn't mean extending. It means referencing a certain element (listview, textview etc.) in your theme. For example, you would have:
<style name="MyTheme.Widget.ListView" parent="#android:style/Widget.ListView.White">
</style>
to define style of your listview.

Categories

Resources