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.
Related
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" >
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?
I have a RelativeLayout with a background set with android:background="#drawable/background".
In my RelativeLayout` I have a standard button but when I run the app in devices running 3.1 or higher the button are displayed transparent.
I have tried setting android:alpha to 1 with no luck.
I know I can make a custom background with selector and shapes but there has to be another way.
Anyone else had this problem?
You'll want to add something like this to your style.xml
Application theme
<style name="ApplicationStyle" parent="android:Theme">
<item name="android:buttonStyle">#style/MyButtons</item>
</style>
Button style
<style name="MyButtons" parent="#android:style/Widget.Button">
<item name="android:textSize">16sp</item>
<item name="android:background">#000000</item>
</style>
Make sure you're setting your theme correctly in the manifest also
<application
android:allowBackup="true"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:theme="#style/Theme.ApplicationStyle" >
When I click the app icons and start to run the apps, it will appear a white screen for 1 sec.
I don't know why.
Is there any idea to clear this white screen and directly go to my activity?
The white/black screen is the window background image.
The window background is shown while e.g. your onCreate() runs and your layouts are being inflated. It can take some time especially if there's a lot of bitmaps that need to be read, decoded and scaled.
Changing the theme works because some themes have a non-default window background. For example, Theme.Wallpaper has a transparent background. There are other definitions there, too. Essentially what you want is:
<style name="YourTheme">
<item name="android:windowBackground">#null</item>
</style>
Programmatically you can achieve the same with
getWindow().setBackgroundDrawable(null);
at the top of activity onCreate().
(Old question but got bumped up by another answer and there wasn't a good answer.)
Settings. File>Settings>Build,Deployment>Instant Run Deselect all options shown there.
and add below line in your style.xml
<item name="android:windowDisablePreview">true</item>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- 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:windowFullscreen">true</item>
<item name="android:windowDisablePreview">true</item>
</style>
apply changes in AndroidMainfest.xml
<application
android:theme="#style/AppTheme">
After I change style.xml:
<resources>
<style name="AppTheme" parent="android:Theme.Wallpaper" />
</resources>
it works!!
Thanks all
Add the following in the manifest file of the corresponding activity
android:launchMode="standard"
and remove android:label="#string/app_name" from the corresponding activity ,this actually helped me
In your manifest.xml file remove the line android:theme="#style/AppTheme" for your app. and check it again
Use this tag in your manifest:
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
In Styles add the following things
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowIsTranslucent">true</item>
Hope this will help you and its working for me
I want to define a default text color for my android app.
I have a base activity class, that all activities are extended from it and I thought this might be a good place to define the colors.
If not what is a better solution? Maybe styles?
Trouble is this, all is new to me, so feel free to advise me and provide code snippets and explanations as well.
This is what my base class looks like. As you can see it's pretty empty
package com.ccslocal.mobile.quiz.jls;
import android.app.Activity;
import android.os.Bundle;
public class BaseActivity extends Activity {
//set up app preferences here
}
As was mentioned in denis.solonenko's answer, the correct approach would be to modify your theme.
Where you define your theme (in your themes.xml or styles.xml file), you'll want to add something like this:
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
...
<item name="android:textColor">#FF00FF</item>
...
</style>
Then make sure that the theme is applied to your Activity or Application in the manifest:
<application
...
android:theme="#style/AppTheme"
....
>
You can also define:
textColor - The default text color of any given view
textColorPrimary - The default text color for enabled buttons and Large Textviews
textColorSecondary - The default text color for Medium and Small Textviews
textColorTertiary - ?
(Source TextColor vs TextColorPrimary vs TextColorSecondary)
Keep in mind that many other things may override these predefined colors, such as applied styles or definitions in different resource folders.
See here for a full list of theme items: https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/values/themes.xml
Create a custom theme for your app. Take look at the official guide.
Yes you are right you can make that using style. Or you can use TextView.getTextColors().getDefaultColor() for set default text color. Actually I never used this but I think it may be help you.
For style
<style name="TextColor">
<item name="android:textColor">#00FF00</item>
</style>
Then in layout file
<TextView style="#style/TextColor" />
Set your default color in your res/values/colors.xml like this
<color name="defaultTextColor">#ffffff</color>
So this color to all your texts
android:textColor="#color/defaultTextColor"
or
textView.setTextColor(R.color.defaultTextColor);
Create style for TextView:
<style name="TextViewTheme">
<item name="android:textColor">#android:color/white</item>
</style>
Apply it in style for App:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:textViewStyle">#style/TextViewTheme</item>
</style>
And remember to change style in AndroidManifest.xml:
<application
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
...
</application>
#android:color/white
yes you can change default color of react native app only add this line in styles.xml file of android src