I am building a mobile app. Everywhere in the app I have the default background colour #F6F6F6. I have this colour stored in colors.xml.
<color name="backgroundColor">#F6F6F6</color>
I am now adding an onboarding guide using ViewPager. So I have an activity with ViewPager and a FrameLayout below with some other stuff in there. The problem is that when the application loads, the ViewPager has a different colour than it should have. It has darker grey #E4E4E4. And the FrameLayout has background just white #FFFFFF. When I set their background colour in the layout to any random colour - red, green, beige, that works and the colour is changed in the app.
Works:
android:background="#color/Red"
But if I try to set the colour to the default background colour or white, it doesn't work. Even if I hardcode the colour. The colour in the app doesn't change. Both views keep the colours I mentioned above.
Doesn't work:
android:background="#F6F6F6"
nor
android:background="#color/backgroundColor"
The app and the activity is using the following theme:
android:theme="#style/AppTheme.NoActionBar"
Why can't I change the background colour to the colours I need?
Try to create a new theme and change the background at theme level.
Note: this an example with a material theme, but it may not differ a lot from the support version.
<!-- themes.xlm -->
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.MyApplication" parent="Theme.MaterialComponents.NoActionBar">
<!-- ... other theme attributes -->
<!-- ... changing theme window background. -->
<item name="android:windowBackground">#color/your_color</item>
<item name="android:colorBackground">#color/your_color</item>
</style>
<!-- ... -->
</resources>
In your activity
<application
...
android:theme="#style/Theme.MyApplication">
<activity
...
android:theme="#style/Theme.MyApplication">
...
</activity>
</application>
Related
I used Android Studio to create basic activity using New -> Activity -> Basic Activity. But the activity background colour is black. I know it is to reduce battery consumption. But is there a way to change it to white colour, without changing style.
I tried to change the background colour of the root layout, but then it won't show hint text of edit text field. Because it's colour is white.
Then I tried to change theme from Material to Material Lite, then it wouldn't show the change when I run the app in the device.
Here is the activity declaration in AndroidManifest.xml
<activity
android:name=".SearchBus"
android:label="#string/title_activity_search_bus"
android:parentActivityName=".MapsActivity"
>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="uk.co.stableweb.iroute.MapsActivity" />
</activity>
In your styles.xml set the android:windowBackground attribute for whatever theme you are using for application or activity. You can find the theme you are using in your AndroidManifest.xml.
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowBackground">#color/somecolor</item>
</style>
</resources>
Note: If you have views in your layout that aren't transparent, it will block you from seeing the color you set here.
Did you try :android:background="#ffffff" i? It works for me
I am trying to customize background and color of Title bar. I have seen many example on android site and stack overflow but nothing worked out for me.
In examples they are adding new elements in title bar but i want to customize existing title bar.
I do not want to change anything else. I only want to change background color and font color of text.
If you are using Android Lollipop (api 21+), you can edit the "styles21.xml" (in the res directory) code and add the following:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Material">
<!-- Customize your theme using Material Design here. -->
<!-- Title Bar color here -->
<item name="android:colorPrimary">#YOUR_COLOR_HERE</item>
<!-- Background color here -->
<item name="android:windowBackground">#YOUR_COLOR_HERE</item>
</style>
</resources>
For more information see Google's "Using the Material Theme" here.
This XML code will work throughout the whole app (each different view) unless otherwise specified.
I hope this is what you are looking for!
I'm having issues creating a Material Design app with the AppCompat v21 theme. First I have my app theme using the AppCompat light with dark actionbar.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="colorPrimary">#color/theme_color</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#color/theme_color_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="colorAccent">#color/theme_color_accent</item>
</style>
The color branding for my app is quite dark which is why I use the DarkActionBar variant. My problem is that I have a couple layouts where I'd like to put a Spinner and an EditText inside a layout where the background is my theme_color which is dark. This results in a Spinner/EditText with black color on a dark background. How can I make the style/theme of these controls use the Dark variant so they show up with white text instead of black text. Even worse than that, I need the spinner to show white text but dropdown items of the spinner to show the light version.
I'm using a Spinner inside a Toolbar with dark background and remembered that the Google I/O Android App does the same, so I looked at its styles - more specifically, the ActionBarThemeOverlay here.
After I used the below attributes on my theme, my Spinner background color (the "arrow") changed:
<item name="colorControlNormal">#fff</item>
<item name="colorControlHighlight">#3fff</item>
colorControlHighlight is the color when the user presses the Spinner. I didn't test on an EditText, though.
So, you're looking for a way to apply a different theme to select views.
There's no xml-only way to do that for most elements (except Toolbar, which you already know)
You'll have to inflate the views manually, using a ContextThemeWrapper:
ContextThemeWrapper wrapper = new ContextThemeWrapper(getActivity(),
R.style.Theme_AppCompat); // The dark one
LayoutInflater footPump = LayoutInflater.from(getActivity()).cloneInContext(wrapper);
// Note null as second argument -- if you pass in parent view, theme will
// be taken from the parent
Spinner spinner = (Spinner) footPump.inflate(R.layout.spinner, null);
to have the layout resource for the inflater, just create a single-view xml file:
<!-- res/layout/spinner.xml -->
<?xml version="1.0" encoding="utf-8"?>
<Spinner xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
How about this..
make a style for you widget, ex:
<style name="CustomEditText" parent="android:Widget.EditText">
<item name="android:textColor">#color/red</item>
</style>
then in your xml add this attribute to your EditText
style="#style/CustomEditText"
I am trying to set the background color for all my entire app and I could not do it. WHat I am doing is this:
<style name="AppTheme" parent="AppBaseTheme"> <!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:windowBackground">#color/holo_gray</item>
<item name="android:colorBackground">#color/holo_gray</item>
</style>
I also tried with:
<item name="android:background">#color/holo_gray</item>
I want to have the same default background color of Api 14 in lower APIs, that light gray.
I know that I could fix it by adding a android:background="#color/holo_gray" in every root layout but I want to do it by style, to avoid repeat this line in all my xml layout.
Thanks in advance,
holo_gray is not work in lower version so you should write you own color instead of it.Making the change in all value folder styles
#color/"holo_gray"(Replace your own color)
If you have ListViews in your layouts, they possess a default white background on 2.2. Try setting android:background="#null" on them, so your window background can show up.
I have an activity with background colour black.
It has edittext and right after soft keyboard goes away, for a moment I see white area under keyboard; and then view gets resized.
This looks like blinking.
Question is, is it possible to set some kind of default background color for entire app? (Assuming that my activity already has background attribute)
windowSoftInputMode is also not an option
If you want to specify the background to your whole application, you may edit the app theme or add custom theme to your application manifest. But this will be overridden when background is specified in the xml layout.
Add custom theme in style.xml
<style name="MyTheme" parent="android:Theme">
<item name="android:background">#android:color/black</item>
</style>
Specify the theme in manifest as
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/MyTheme" >
Adding theme for each activity in manifest
<activity
android:name=".Login"
android:configChanges="orientation"
android:theme="#style/MyTheme>
</activity>
You can also modify the existing theme in style.xml which is already defined in manifest by changing the background as desired
<item name="android:background">#android:color/black</item>