I'm struggling to override the default themes app bar color properly.
When I use the android:actionBarStyle it changes the color but then the title text is missing.
<resources>
<style name="ToolbarThemeStyle" parent="android:Theme.Material.Light">
<item name="android:actionBarStyle">#style/ActionBarTitle.Background</item>
</style>
<style name="ActionBarTitle.Background" parent="">
<item name="android:background">#8DC44E</item>
<item name="android:titleTextStyle">#style/ActionBarTitle.Text</item>
</style>
<style name="ActionBarTitle.Text" parent="">
<item name="android:textColor">#FFFFFF</item>
</style>
</resources>
I've tried Replacing the Action Bar but I'm wondering if there's not a shorter and easier way.
Manifest:
<application android:label="Home Automation" android:icon="#mipmap/ic_launcher" android:theme="#android:style/Theme.Material.Light"
</application>
Activity:
[Activity(Label = "Label", MainLauncher = false, Theme = "#style/ToolbarThemeStyle", NoHistory =true)]
Thanks all for your replies. I thought I'd answer this myself whereas I've spent hours trying to figure this out.
The obvious solution was in this page under Using Custom Themes but I was getting the error "No resource found that matches the given name (android:color Primary)". Changing android:minSDKVersion=23 also did not work.
I went to Application Properties and set the "Compile using Android version" to the current targeting framework (i.e. API 23) instead of the maximum which was not installed yet set to API 25.
make sure are you setting theme to activity in menifest or xml. Here I am sharing my theme code you can refer.
<style name="MaterialAppTheme" parent="Theme.AppCompat.Light">
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#color/white</item>
<item name="android:textColorSecondary">#color/red</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
This code should be in you style.xml
<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" />
</resources>
And make sure you should have declared it in manifest.xml
<application
android:name=".app.AppController"
android:allowBackup="true"
android:icon="#drawable/images"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
Related
To moderators: this is not a duplicate question. I've tried all avail. solutions from StackOverflow.
I've used Theme.MaterialComponents.Light.NoActionbar as a parent theme in styles.xml file.
my styles.xml:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:navigationBarColor">#00000000</item>
<item name="snackbarStyle">#style/MySnackbar</item>
</style>
<style name="AppTheme2" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:navigationBarColor">#00000000</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="snackbarStyle">#style/MySnackbar</item>
</style>
</resources>
My application class code:
public class Extendit extends Application {
#Override
public void onCreate() {
super.onCreate();
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
}
The application class is attached in the manifest file. Also, the AppTheme is the base theme of application.
androidmanifest.xml:
<application
android:name=".Extendit"
android:allowBackup="true"
android:appComponentFactory="df"
android:icon="#mipmap/iconx"
android:label="#string/app_name"
android:largeHeap="true"
android:roundIcon="#mipmap/iconx"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:replace="android:appComponentFactory">
I've also added "forcedarkallowed" false flag in styles.xml and deleted the styles.xml(night) file.
P.S. I'm using Realme device.
Got the fact. The issue is with device and Realme Android 9.0 OS. It doesn't allow you to have your own day or night theme in any way, rather it forces you to have what the system is currently having.
Add this in your styles.xml file:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
</style>
And in your AppTheme use this in parent:
parent="Theme.MaterialComponents.Light.DarkActionBar"
I have a main Activity, and I am loading Fragments inside it.
I do not want the ActionBar, so I have hidden it in Manifest as follows
android:theme="#style/NoActionBar"
When I populate a Fragment, the ActionBar is hidden, but it gives a black portion on the bottom of the screen and I can't even use that specific portion in my layout.
Any help?
Replace your style.xml with below code:
<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>
</resources>
and then set theme as
android:theme="#style/AppTheme.NoActionBar"
In my project we are using that kind of style:
<style name="NoActionBarTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">#color/black</item>
</style>
in AndroidManifest.xml you set it like
<application ...
android:theme="#style/NoActionBarTheme">...
When I apply the auto-generated AppTheme.NoActionBar to my activity via android:theme like so:
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mypackage">
<application
...
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:theme="#style/AppTheme.NoActionBar" />
</application>
</manifest>
My MainActivity is rendered with a transparent status bar at the top, which eventually has a white background, and white text over it. If the device is charging, that is the only symbol to be seen.
Transparent ActionBar from AppTheme.NoActionBar
Here is my values/styles.xml:
<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"/>
</resources>
In the second style, you can see AppTheme.NoActionBar, which by default inherits AppTheme, however nowhere in either style specifies that the status bar should be transparent.
Chances are, if you've come across this issue, you have a folder called values-v21 and in it a file called styles.xml. This file defines styling for devices using API 21+ (Android 5.0+). This file will also most likely contain the following style named AppTheme.NoActionBar. Sound familiar?
values-v21/styles.xml:
<resources>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
</resources>
AppTheme.NoActionBar was defined in the values/styles.xml provided in the question, which is still valid, however that file is only used for devices under API 21. If you look at the code, you can immediately identify the issue just by seeing the word transparent towards the very end. A little to the left and we see statusBarColor and voila. That's the issue. If you do not which to provide this styling for more up-to-date users you can simply remove that line of styling.
values-v21/styles.xml:
<resources>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
</resources>
And here's the result of that style removal:
Good ol' opaque status bar
How do i change the Overflow Menu icon on the far right of the action bar as seen in the image below? My Holo theme specifies this 3 row black stack icon by default and i want something else. i can't seem to find a solution for this. I have looked at the documentation on http://developer.android.com/guide/topics/ui/menus.html but it doesn't seem to lend much help.
Thanks!
You can try something like this:
<style name="MyTheme" parent="android:style/Theme.Holo.Light">
<item name="android:actionOverflowButtonStyle">#style/MyActionButtonOverflow</item>
</style>
<style name="MyActionButtonOverflow" parent="android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">#drawable/my_action_bTutton_overflow</item>
</style>
and in AndroidManifest.xml
<application
android:theme="#style/MyTheme" >
Define a custom style: for example, let's call it customoverflow.
In this style you set android:src to the picture you would like to use.
Now create a style with parent Theme.holo.
In this style you need to define:
<item name="android:actionOverflowButtonStyle">#style/customoverflow</item>
I just tested this and it works.
If you are using AppCompat you can achieve by following code.
res/values/themes.xml
<style name="MyTheme" parent="#style/Theme.AppCompat.Light">
<item name="android:actionOverflowButtonStyle">#style/ActionButtonOverflow</item>
<!-- Support library compatibility -->
<item name="actionOverflowButtonStyle">#style/ActionButtonOverflow</item>
</style>
<style name="ActionButtonOverflow" parent="#style/Widget.AppCompat.ActionButton.Overflow">
<item name="android:src">#drawable/ic_launcher</item>
</style>
and in androidmanifest.xml
<application
android:theme="#style/MyTheme" >
I noticed that it becomes white if the theme of the app is Holo, but it is blackish when the theme is Holo.Light
However, changing the style of the action bar to inherit from Holo and the rest of the app from Holo.Light does not solve the problem, but it should point in the direction of which style you should be modifying.
What I have tried is:
<style name="AppThemeLight" parent="android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="android:windowContentOverlay">#drawable/actionbar_shadow</item>
</style>
<style name="ActionBar" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/header_brown</item>
<item name="android:titleTextStyle">#style/ActionBarTitle</item>
<item name="android:icon">#drawable/header</item>
</style>
I have the same problem and I think this is close to a solution
Duplicate question,
Changing overflow icon in the action bar
This is my answer as below,
Change your custom overflow icon of Actionbar in styles.xml
<resources>
<!-- Base application theme. -->
<style name=“MyTheme" parent="#android:style/Theme.Holo">
<!-- Pointer to Overflow style DONT forget! -->
<item name="android:actionOverflowButtonStyle">#style/MyOverFlow</item>
</style>
<!-- Styles -->
<style name="MyOverFlow" parent="#android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">#drawable/ic_your_action_overflow</item>
</style>
</resources>
Put custom theme "MyTheme" in application tag of AndroidManifest.xml
<application
android:name="com.example.android.MainApp"
android:theme="#style/AppTheme">
</application>
Have fun.#.#
Shalafi's solution works with a few changes! You will need to specifiy theme.Holo as the parent for the theme but it has the downside of changing the default text color(at least in my styles).
The amended code should be:
<style name="AppThemeLight" parent="android:style/Theme.Holo">
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="android:windowContentOverlay">#drawable/actionbar_shadow</item>
</style>
<style name="ActionBar" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/header_brown</item>
<item name="android:titleTextStyle">#style/ActionBarTitle</item>
<item name="android:icon">#drawable/header</item>
</style>
Basically Theme customizations available in newer API levels can go in res/values-vXX/styles.xml, while customizations related to backward-compatibility can go values/styles.xml
Shalafi's solution works with a few additions:So
add this code to both res/values-vXX/styles.xml and res/values/styles.xml and this will work like Magic!
<style name="AppTheme" parent="android:style/Theme.Holo.Light">
<item name="android:actionOverflowButtonStyle">#style/MyActionButtonOverflow</item>
</style>
<style name="MyActionButtonOverflow"parent="android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">#drawable/your_overflow_icon</item>
</style>
also add it in AndroidManifest.xml
<application
android:theme="#style/AppTheme" >
<style name="ToolBarTheme" parent="ThemeOverlay.AppCompat.ActionBar">
<item name="android:tint">#color/colorAccent</item>
create the above theme.set tint with your color and add this theme to the toolbar.
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ToolBarTheme"/>
I have a style applied to my whole application:
AndroidManifest.xml:
<application android:theme="#style/ApplicationStyle" android:icon="#drawable/icon" android:label="#string/app_name">
And in my styles.xml:
<style name="ApplicationStyle" parent="android:Theme">
<item name="android:button">#style/CKButton</item>
</style>
<style name="CKButton" parent="android:style/Widget.Button">
<item name="android:textSize">19sp</item>
<item name="android:layout_margin">0dip</item>
<item name="android:background">#ff0000</item>
</style>
But the style doesn't get applied.
I'm sorry if I just used the false name in the ApplicationStyle - Item, but I have no clue where to look for the object names and simply assumed, that android:button applies to all buttons.
For Android styles, you reference the preset attributes that Android has laid out in R.attr. In this case, it looks like you want to to reference android:buttonStyle. I think this would work:
<style name="ApplicationStyle" parent="android:Theme">
<item name="android:buttonStyle">#style/CKButton</item>
</style>
For Material components theme it would be like this:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="materialButtonStyle">#style/AppTheme.Button</item>
</style>