Difference between style.xml and theme.xml android studio? - android

Hey I'm trying to change the background of my action bar but I'm not quiet sure I understand the structure of the style files. So basically I have style.xml which is to pass on some elements a desired style. Then I've Theme.xml which is to have a group of styles in it, correct ? How do you link the two in other words how do I tell the theme I want the specified style in it ? I can't manage to change the background of the action bar so here is my code:
style.xml:
<!-- Base application theme. -->
<style name="MyActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:colorBackground">#color/color_lightBlue</item>
</style>
</resources>
theme.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyCustomTheme" parent="Theme.AppCompat.Light">
</style>
</resources>
and wtf is v11/style ?

Whether you put the attributes in styles.xml or theme.xml, they have the same effect finally if you apply the theme to your app or activity. In your AndroidManifest.xml, in order to let the theme have the effect you want, you should apply your customized theme like following to your app.
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >

Related

action bar does not show After applying theme

This my style page:
<resources>
<color name="for_custom">#ff4db0e8</color>
<style name="CustomTheme" parent="android:Theme.Light">
<item name="android:windowBackground">#color/for_custom</item>
<item name="android:actionBarTheme">#color/for_custom</item>
<item name="android:displayOptions">homeAsUp</item>
</style>
</resources>
And this is my manifest:
<application android:label="#string/app_name" android:icon="#mipmap/ic_launcher" android:theme="#style/CustomTheme">
action bar does not show After applying theme.Why?
What is my mistake?
If you are on Lollypop+ the default Theme is Material, which does not show the ActionBar. This is because the Material Design spec remarks the Toolbar view as the new way to keep the buttons. If you want the old style, use Theme.Holo.Light instead of just Theme.Light

Changing Android action bar background colour

For some reason this setup just gives me the default action bar background colour.
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#d73830</item>
</style>
</resources>
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
...
</application>
In activity_main.xml my theme is set to 'AppTheme'.
You have wrong parent of MyActionBar.
It must be from AppCompat, like next:
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background" tools:ignore="NewApi">#color/red</item>
<item name="background">#color/red</item>
</style>
What you can do is to use hash code of colour.Here is how.Go to this web page
http://www.color-hex.com
Choose a colour you wish and after copy the code of that colour and later paste into your background section.In general lets say you want your background colour of your screen to be red so you must declare it in xml layout file like this
android:background = "#FF0508"/>
You can declare this code almost everywhere where you want to change exact things colour and for my opinion its the easiest way.Why not?you got a webpage where you can get colour code and you can use it with a single line everywhere.Delicios isn't it?

set background Image to whole application in android

I want to set background image to my application in android. So my application already has a theme set in my manifest file like this
<application android:theme="#android:style/Theme.NoTitleBar" />
Now this was implemented from the themes of android package.
Now i want to add a background image to my entire application how can i do it.
<style name="Theme.NoTitleBar.BackgroundImage">
<item name="android:background">#drawable/bitzer_background</item>
</style>
I want the Theme.NoTitleBar as well.
I have changed the style below, by doing this I am overriding the Theme.NoTitlteBar
<style name="Background" parent="#android:style/Theme.NoTitleBar">
<item name="android:windowBackground">#android:color/black</item>
<item name="android:windowNoTitle">true</item>
</style>
Now my manifest file looks like this:
<application android:theme="#style/Background"/>
You have to use styles to achieve this
Check out this link
Create a theme with your background and use that theme.

How to change menu theme in Android

My android application uses the following style:
<style name="AppTheme"
parent="android:style/Theme.Holo" ></style>
It is assigned for the whole application in the AndroidManifest.xml file :
<application
android:theme="#style/AppTheme"
[...]
Using this style, menus look like this :
However, if I use the light theme instead :
<style name="AppTheme"
parent="android:style/Theme.Light" ></style>
Menus will look like this :
My question is :
How can I apply the HOLO theme for the whole application and use only the LIGHT theme for menus ??
I just want to apply the dialog "style" of the LIGHT theme and apply the HOLO theme for everything else.
I believe you are looking for this:
<application
android:theme="#style/theme.holo.light>
Try to use "android:itemBackground" to change the background color of the menus
You can make your own white style. Put this into style.xml and give theme in AndroidManifest file this theme
<style name="MyGow.Default.NoActionBar" parent="Theme.AppCompat.Light">
<item name="colorControlNormal">#color/silver</item>
<item name="android:actionModeBackground">#color/white</item>
</style>

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