I try to change the default color of the popup menu by using styles:
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:popupMenuStyle">#style/PopUp</item>
</style>
<style name="PopUp" parent="#android:style/Widget.PopupMenu">
<item name="android:popupBackground">#color/white</item>
</style>
I have hooked up this theme in app manifest.
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19"/>
<application
android:name=".MyApplication"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
However this does not change the default grey background of the popup. Any ideas whats wrong?
I changed
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:popupMenuStyle">#style/PopUp</item>
</style>
to
<style name="AppTheme" parent="android:Theme.Holo.Light">
<item name="android:popupMenuStyle">#style/PopUp</item>
</style>
now it works. However it seems that using android:Theme.Holo.Light.DarkActionBar you cannot change the style of the popup through xml.
Related
I have base theme
<style name="BaseAppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="colorPrimary">#color/color_primary</item>
...
</style>
and AppTheme that inherits it
<style name="AppTheme" parent="BaseAppTheme" >
<item name="colorPrimary">#FFFF0000</item>
<item name="android:statusBarColor">#color/transparent</item>
</style>
and is used as the main theme of the app, i.e.
<application
...
android:theme="#style/AppTheme"
...
>
<activity
android:name=".MainActivity"
android:theme="#style/AppTheme"/>
</application>
The problem is that attributes (eg <item name="colorPrimary">#FFFF0000</item> or <item name="android:statusBarColor">#color/transparent</item>, all of them) in AppTheme are ignored. However, if I add them to BaseAppTheme then they will work. Why are attributes ignored in AppTheme and how to fix it?
Do you have AppTheme only in values/styles.xml? Maybe do you have values-v21/styles.xml that contains AppTheme also so the problem is there or something like this?
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">
I am trying to change the background color of the Popup menu in the action bar.
Everything that I try its always the same black color, that is by default.
This is what I have in my styles.xml
<style name="AppTheme" parent="Theme.AppCompat">
<item name="colorPrimary">#color/app_navbar_background</item>
<item name="colorPrimaryDark">#color/app_navbar_background</item>
<item name="colorAccent">#color/CadetBlue</item>
<item name="android:textColorSecondary">#color/black</item>
<item name="android:popupMenuStyle">#style/PopupMenu</item>
</style>
<style name="PopupMenu" parent="#android:style/Widget.PopupMenu">
<item name="android:popupBackground">#color/MediumPurple</item>
</style>
And I do have the theme set in the AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
Does anybody know what I could be doing wrong
Try using this:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->
<item name="android:itemBackground">#color/app_navbar_background</item>
</style>
It's possible to change titelbar appearence? i would make it transparent and change default settings icon with a custom image. This is how my theme is write:
<style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowBackground">#drawable/my_bg</item>
</style>
<style name="AppTheme" parent="#android:style/Theme.DeviceDefault">
<item name="android:textColor">#colorhere</item>
<item name="android:windowTitleBackgroundStyle">#style/WindowTitleBackground</item>
</style>
<style name="WindowTitleBackground">
<item name="android:background">#colorhere</item>
</style>
and don't forget to check
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
Take a look at the Android Action Bar Style Generator, it is a very useful tool for styling your Action Bar.
I'm a beginner in Android development and I trying to build my theme but I have a problem. I tried searching answers on google, d.android but to no avail.
ActionBar is changing color (this is OK), but text and icon of app doesn't show (only if I use my theme - if I use default theme everything is OK). Why?
res/values/styles.xml:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="AppTheme">
<item name="android:background">HEX COLOR</item>
<item name="android:titleTextStyle">#style/MyTitleTextStyle</item>
</style>
<style name="MyTitleTextStyle" parent="AppTheme">
<item name="android:textColor">#FFFFFF</item>
</style>
</resources>
Here is my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.appname"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.appname.Intro"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
"You should add following code in onCreate() method.
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.ic_launcher); "
I see the problem that you use AppTheme as parent for MyActionBar style and it causes circular dependency. MyActionBar -> AppTheme -> MyActionBar ... You should use android:Widget.ActionBar or similar as parent of your action bar theme.
Also there should be android:Theme.Holo.Light instead of android:Theme.Light as parent of AppBaseTheme.
Here is how your res/values/styles.xml file should look like:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="android:Theme.Holo.Light"/>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="android:Widget.ActionBar">
<item name="android:background">HEX COLOR</item>
<item name="android:titleTextStyle">#style/MyTitleTextStyle</item>
</style>
<style name="MyTitleTextStyle" parent="AppTheme">
<item name="android:textColor">#FFFFFF</item>
</style>
</resources>