My styles.xml file is refusing to work. What am i doing wrong? It says expected closing tag and needs attribute value...
<!-- Base application theme. -->
<style name="Theme.MainTheme" parent="Theme.AppCompat.Light">
<!-- colorPrimary is used for the default action bar background -->
<item name=”colorPrimary”>#colors/Primary</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name=”colorPrimaryDark”>#colors/PrimaryDark</item>
<!-- colorAccent is used as the default value for colorControlActivated, which is used to tint widgets -->
<item name=”colorAccent”>#colors/Accent</item>
</style>
colors.xml (stored in res\values)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="Primary">#03A9F4</color>
<color name="PrimaryDark">#0288D1</color>
<color name="Accent">#1DE9B6</color>
</resources>
You need to say #color instead of #colors. Colors is the name of your colors.xml file, however you are seeking the color resources, which you access using #color
<item name="colorPrimary">#color/Primary</item>
Related
It is my first time programming in android and I want to change the color of the bars, I read the documentation it seems simple but it does not work for me.
I am going to show what I add but if you need more information I will post it.
Window window = getWindow();
window.setStatusBarColor(R.color.colorWhite);
window.setNavigationBarColor(R.color.colorWhite);
All it does is clarify the bar
I think you might like to have a look at this
https://stackoverflow.com/questions/39341818/how-to-change-the-color-of-the-status-bar-in-android/39341866#:~:text=You%20can%20change%20it%20by,xml.&text=On%20API%20level%2021%2B%20you,setStatusBarColor()%20method%20from%20code.
It appears that you're doing fine but something is missing
From java class:
Get color by calling resources, do this way:
Window window = getWindow();
window.setStatusBarColor(getResources().getColor(R.color.colorWhite));
window.setNavigationBarColor(getResources().getColor(R.color.colorSome));
This color can be changed from your AppTheme in styles.xml file. It's value can be changed from attribute <item name="colorPrimaryDark">#yourColor</item>
styles.xml:
<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>
</style>
Their colors are available in colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
Read the documentation.
I have to change the element color and text color of status bar and I also have to change the text color of title bar in Android:
The existing code is as follows:
styles.xml
<style name="AppThemeNew" 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:statusBarColor">#color/status_bar_color</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#FDFEFE</color>
<color name="colorPrimaryDark">#F4F6F6</color>
<color name="colorAccent">#088da5</color>
<color name="status_bar_color">#F4F6F6</color>
<color name="status_bar_element_color">#AAB7B8</color>
</resources>
row_data.xml
Layout
Please help.....
To change statusbar' element and text color, you could create custom theme like this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:statusBarColor">#color/status_bar_color</item>
<item name="android:windowLightStatusBar">false</item>
</style>
Notes:
status_bar_color would be your custom color resource.
android:windowLightStatusBar = true, status bar text color will be
compatible (grey) when status bar color is light.
android:windowLightStatusBar = false, status bar text color will
be compatible (white) when status bar color is dark.
ref is here
Tested in above api level 23
The action bar takes the colour for the titles and icons from textColorPrimary
However this will also affect the default text for edit texts and text views if you set it on the app theme.
To get around this create a separate theme for the app bar that includes the text colour change and either reference it in the app theme as the app bar style or set it on the toolbar in the XML if you have a custom toolbar.
How can I change the color of the tab title background? The standard color is blue. How can I change it to white? Like here: https://www.androidpolice.com/wp-content/uploads/2014/10/nexus2cee_43.png
Customize the default theme
For example, your styles.xml file should look similar to this:
<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>
</style>
Once you know your colors, update the values in res/values/colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- color for the app bar and other primary UI elements -->
<color name="colorPrimary">#3F51B5</color>
<!-- a darker variant of the primary color, used for
the status bar (on Android 5.0+) and contextual app bars -->
<color name="colorPrimaryDark">#303F9F</color>
<!-- a secondary color for controls like checkboxes and text fields -->
<color name="colorAccent">#FF4081</color>
</resources>
override whatever other styles you want
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
...
<item name="android:windowBackground">#color/activityBackground</item>
</style>
Cited from: https://developer.android.com/guide/topics/ui/look-and-feel/themes.html#CustomizeTheme
Programatically:
You can call method and set the Theme in AndroidManifest.xml.
<application
android:name=".Class.App"
android:icon="#mipmap/ic_test"
android:theme="#style/AppTheme" <-- Add your custom theme here
</application>
So I have set the colors i.e primary, primaryDark, accentColor in the style.xml manually and I can see whole application is taking the colors properly such as toolbar is having the appropriate colors, texts are having appropriate colors. Now, when I am creating a dialogue by java code the colors of the buttons within fragment are very much different from the colors my whole application is having. So why the dialogue is having such different style than of my application. This question will help me in understanding themes, so please answer in such way i.e. behaviour of the themes in android.
EDIT
The code I am using in styles.xml in my application.
<resources>
<!-- Base application theme. -->
<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>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
The code I am using in colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#675217</color>
<color name="colorPrimaryDark">#261e09</color>
<color name="colorAccent">#ffcb39</color>
<color name="colorTabLayout">#a68425</color>
</resources>
Here are the screenshots of the things I am facing.
First Screen:-
Every thing is fine all the elements have appropriate colors
Second Screen:-
Here The color of the buttons in the pop up dialogue is not the accent color that I have added in styles.xml. Otherwise in first screen you can see different accent color in button text in cardview.
<style name="Theme_Base_App" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
I simply copied the above code to my styles.xml file and I copied
android:theme="#style/Theme_Base_App"
into my manifest file. How do I now change the color of this action bar?
Also, can someone explain me what exactly I am doing by using these lines of code? What is the manifest file for? And what am I doing in the Styles.xml file?
To change your color just set the colorPrimary in your colors.xml file.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="primary">your color</color>
</resources>
Using this style you are defining your custom theme inheriting from AppCompat theme.
<!-- inherit from the material theme -->
<style name="Theme_Base_App" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="colorPrimary">#color/colorPrimary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
</style>
You can refer this link for more info.
The Android Manifest file presents essential information about your app to the Android system. With
android:theme
you are defining a reference to a style resource defining a default theme for all activities in the application. Individual activities can override the default by setting their own theme attributes. For more information, see the Styles and Themes developer guide.
Here you can find more info about Manifest and application element in the Manifest.