android overflow menu item text not displayed - android

See end of post for a workaround
I added an overflow menu to my main Android Action. However when pressing the [...] in the top right corner, the PopupMenu does not display the menu items correctly. They are left blank, see the image, it should contait 2 menu items with the strings "Manage" and "About":
This problem only arises for the MainActivity, i.e. the Activity starting at application launch. A secondary Activity, that is spawned later, correctly displays menu items.
The Items do get added to the menue somehow, since the box changes its size with more/less menu items. Also I do get a response when clicking where a menu item is supposed to be, e.g. show a Toast with some text.
Adding the menu items with showAsAction="always" will display the item correctly with it's icon in the ActionBar.
The MainActivity was initially created as a PageView Activity, the Toolbar was then later added to it's layout.
Edit
Making the menu items checkable with android:checkable="true" will show a checkbox next to the empty spot where the text is supposed to be.
layout/main_activity.xml:
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/Theme.PickupList.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="#+id/main_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme" />
<com.google.android.material.tabs.TabLayout
android:id="#+id/main_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:tabIndicatorColor="#color/purple_200"
app:tabTextColor="#color/teal_200" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:id="#+id/main_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
layout/main_menu.xml:
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/mainmenu_manage"
android:icon="#android:drawable/ic_menu_manage"
android:title="#string/activitymain_menu_manage" />
<item
android:id="#+id/mainmenu_about"
android:icon="#android:drawable/ic_menu_info_details"
android:title="#string/activitymain_menu_abount" />
</menu>
themes/themes.xml (almost unchanged):
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.PickupList" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_500</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_700</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
<style name="Theme.PickupList.ActionBar">
<item name="windowActionBar">true</item>
<item name="windowNoTitle">true</item>
</style>
<style name="Theme.PickupList.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="Theme.PickupList.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
MainAction.java:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//...
Toolbar toolbar = findViewById(R.id.main_toolbar);
setSupportActionBar(toolbar);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
// works fine
if (id == R.id.mainmenu_about) {
Toast.makeText(this, "about", Toast.LENGTH_SHORT).show();
return true;
} else if (id == R.id.mainmenu_manage) {
Toast.makeText(this, "manage", Toast.LENGTH_SHORT).show();
return true;
}
return super.onOptionsItemSelected(item);
}
}
Sorry for the code-dump. I am at my wits end with what else I can do here.
Edit / Workaround:
So in the end I came up with a workaround.
I manually added a menu item with the icon for the overflow menu to the Toolbar and set its showAsAction="always" property.
In the click handler I then create custom PopupMenu and anchor it to the Toolbar with Gravity.END.
The PopupMenu will then display it's items correctly.
I do not mark this solution as an answer, although it effectively solves my problem. It solves the problem with the bad aftertaste, that the android api has defeated me and I still have hope that I (or someone else) sees an error and comes up with a solution that uses the internal overflow menu mechanics.

I just got the same problem you described, no ripple effect whatsoever, but got a response while clicking in the white box from the menu.
Fixed it by adding the following line in my styles.xml
<item name="android:textColor">#000000</item>

Related

How can I override my menu bar to come on my application bar?

I have recycler view + viewpager + toolbar in my activity. When I long click on the row in recycler view it should show me a menu bar with a delete option. But this is what I get. Any ideas as to why it is coming above my application name?
This is the xml of my main activity:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.kaad.sampleproject.MainActivity">
<android.support.v7.widget.Toolbar
android:id="#+id/main_activity_tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="#+id/main_activity_tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/main_activity_tool_bar"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:tabIndicatorColor="#ff00ff"
app:tabMode="fixed"
app:tabSelectedTextColor="#ffffff"
app:tabTextColor="#d3d3d3" />
<android.support.v4.view.ViewPager
android:id="#+id/main_activity_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/main_activity_tablayout" />
</RelativeLayout>
I kept an add and about menu which never gets displayed for some reason:
Here is the xml of both my menus:
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/menu_bar_main"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
tools:context=".MainActivity">
<item
android:id="#+id/menu_item_new"
android:icon="#drawable/ic_add_white_36dp"
android:title="#string/menu_new"
app:showAsAction="ifRoom|withText" />
<item
android:id="#+id/menu_item_about"
android:title="#string/menu_about"
app:showAsAction="never" />
</menu>
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/menu_bar_delete"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
tools:context=".MainActivity">
<item android:id="#+id/menu_item_delete"
android:icon="#android:drawable/ic_menu_delete"
android:title="#string/delete" />
</menu>
The xml of my styles
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!--<item name="colorPrimary">#FF595951</item>-->
<!--<item name="colorPrimaryDark">#FF5C5C5C</item>-->
<!--<item name="colorAccent">#FFCCCCCC</item>-->
<!--<item name="android:textColorPrimary">#FF0FF0</item>-->
<item name="windowActionBar">true</item>
<item name="windowNoTitle">true</item>
</style>
This is Main Activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_main);
database = new Database(this);
categories = database.getCategories();
myToolbar = (Toolbar) findViewById(R.id.main_activity_tool_bar);
setSupportActionBar(myToolbar);
// Get the ViewPager and set it's PagerAdapter so that it can display items
myViewPager = (ViewPager) findViewById(R.id.main_activity_viewpager);
myPagerAdapter = new MyPagerAdapter(getSupportFragmentManager(), MyMainActivity.this, categories);
myViewPager.setAdapter(myPagerAdapter);
// Give the TabLayout the ViewPager
myTabLayout = (TabLayout) findViewById(R.id.main_activity_tablayout);
myTabLayout.setupWithViewPager(myViewPager);
// Iterate over all tabs and set the custom view
for (int i = 0; i < myTabLayout.getTabCount(); i++) {
TabLayout.Tab myTab = myTabLayout.getTabAt(i);
myTab.setCustomView(myPagerAdapter.getTabView(i));
}
bus.getInstance().register(this);
}
This is how I am calling my menu bar in my main prescription fragment
public class CustomMultiSelectorCallback extends ModalMultiSelectorCallback {
private int count;
public CustomMultiSelectorCallback(MultiSelector multiSelector) {
super(multiSelector);
}
#Override
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
super.onCreateActionMode(actionMode, menu);
count = 0;
actionMode.getMenuInflater().inflate(R.menu.list_item_delete, menu);
return true;
}
Issue for About button:
<item
android:id="#+id/menu_item_about"
android:title="#string/menu_about"
app:showAsAction="never" />
update the never part to "ifRoom"
Regarding the menu appearing, can you be more explicit, as to me it seems in Relative Layout you wanted the Toolbar to be top and the views to come after it and that is what it shows.
So I have solved one of the problems. This is what I edited in my code to display add and about buttons in the toolbar.
First, in your onCreate in the fragments, add this line:
setHasOptionsMenu(true);
Second, in your styles, change your theme to something which has NoActionBar. In my case I did this:
<style name="AppThemeOfStyles"parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#FF595951</item>
<item name="colorPrimaryDark">#FF5C5C5C</item>
<item name="colorAccent">#FFCCCCCC</item>
<item name="android:textColorPrimary">#FF0FF0</item>
<item name="windowActionBar">true</item>
<item name="windowNoTitle">true</item>
</style>
I also changed the name of my theme from AppTheme to AppTheme of styles since AppTheme is already a theme defined. So better to change your theme name to something else.
This leads us to the result below:
But my delete is still coming on the top of the toolbar on longpress.
Any suggestions, advice will be appreciated :)
UPDATED:
Use this in your theme for the overlay to work:
<item name="windowActionModeOverlay">true</item>
Here is the end result:

Toolbar going on top of Appbar - CoordinatorLayout

I've been struggling with the AppBarLayout/Toolbar/CoordinatorView. Want the Toolbar to slide up on scroll, and return immediately on scroll down (like most reading apps, g+ is an example also). However, this is what I'm getting:
Normal:
A little scroll:
Full scroll:
This is my code:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="main.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/id_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="#+id/id_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
android:title="Hello World"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/main__activitycontent"/>
</android.support.design.widget.CoordinatorLayout>
main__activitycontent:
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="main.MainActivity"
tools:showIn="#layout/main__activity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/text_margin"
android:text="#string/large_text"/>
</android.support.v4.widget.NestedScrollView>
I've been reading a lot of blog posts, but none of their configs seems to work for me. The hide on scroll up/show on scroll down works fine, only the Toolbar is moving over the appbar. Checking the Android View Hierarchy I see that they the Toolbar is above the dark blue appbar, and they move up together.
EDIT 1
Removing the fitsSytemWindows=true from the CoordinatorLayout leads to the expected behavior, but the appbar becomes white, no matter the bg color for the CoordinatorLayout:
My guess is that the behavior actually didn't change, what happend is that it doesn't cover the appbar anymore, so the toolbar doesn't go over it.
EDIT 2
<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>
EDIT 3
package main;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import com.ee.oef.refactor.R;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main__activity);
Toolbar toolbar = (Toolbar) findViewById(R.id.main__toolbar);
setSupportActionBar(toolbar);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main__menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
The problem is in the:
app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
Which you could add this to your CollapsingToolbarLayout.enterAlwaysCollapsed is a good practice for CollapsingToolbarLayout and not the Toolbar.
UPDATE: And i've seen few problems in the layouts and the ids.
For example, not sure you saw that or not but i'll explain that.The first thing is, Toolbar's id: id_toolbar which in the onCreate is:
Toolbar toolbar = (Toolbar) findViewById(R.id.main__toolbar);
So, just change it to:
<android.support.v7.widget.Toolbar
android:id="#+id/main__toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
P.s: i just deleted the title and Scrollflag which the title is coming from Manifest -> android:label and you need to change it.(if you want to change it, do it programmatically.)
and return immediately on scroll down (like most reading apps, g+ is
an example also).
Just add this to your Toolbar:
app:layout_scrollFlags="scroll|enterAlways"
And finally, here you can see my answer about this one: https://stackoverflow.com/a/35241363/4409113
Which we have:
Update: I didn't use:
android:fitsSystemWindows="true"
In the CoordinatorLayout too. as you can see the example here:
https://github.com/chrisbanes/cheesesquare/blob/master/app/src/main/res/layout/include_list_viewpager.xml
Update:
To solve the white toolbar problem, set on values-v21/styles.xml:
<item name="android:statusBarColor">#color/colorPrimaryDark</item>
This gives the appropriate behavior AND appearance.

Android - Popup menu don't display below menu action bar

I created a menu and popup menu like picture below (I get in internet and edit by paint), I don't know why it doesn't display normal http://i.imgur.com/jHPobCH.png. I want the interface like this http://i.imgur.com/08XomVV.png and moever, how do I change popup menu background color? I tried as below but not success. I test on Samsung Galaxy J and android 4.4.2.
MainActivity.java
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/webView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
menu_main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
<item android:id="#+id/action_filter"
android:icon="#drawable/ic_filter_white_18dp"
android:title="#string/action_filter"
app:showAsAction="ifRoom" />
<item android:id="#+id/action_label"
android:icon="#drawable/ic_add_circle_outline_white_18dp"
android:title="#string/action_label"
app:showAsAction="ifRoom" />
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
app:showAsAction="never" />
</menu>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
<item android:id="#+id/action_filter"
android:icon="#drawable/ic_filter_white_18dp"
android:title="#string/action_filter"
app:showAsAction="ifRoom" />
<item android:id="#+id/action_label"
android:icon="#drawable/ic_add_circle_outline_white_18dp"
android:title="#string/action_label"
app:showAsAction="ifRoom" />
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
app:showAsAction="never" />
</menu>
styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:background">#3079EB</item>
<item name="android:popupMenuStyle">#style/PopupMenu</item>
</style>
<style name="PopupMenu" parent="Widget.AppCompat.Light.PopupMenu">
<item name="android:popupBackground">#android:color/white</item>
</style>
P/S: I'm a beginner android development it
Can you please post Your entire code here . From the first look what i can understand is the height of the layout where you are populating the popup menu is much high . So even after populating the four items , its having enough of empty space . Change the layout_height of the layout where you are inflating the popup to wrap-content instead of using some fixed height . I hope that will solve the issue .

A blank bar appear at bottom when using translucent status bar in non-actionbar activity?

I want to use a Toolbar instead of an Actionbar with translucent status bar, but a thin bar(the same as the status bar in width) appears at bottom of the screen only if I'm using the NoAcitionbar theme.
And the color of the bar is the same as the 'windowBackgroud' I set. So I guess there's a margin or something.
I tried to reset all the margins but it didn't work.
And when I use the 'Android Device Monitor' in Android Studio to check the hierarchy of the UI the bar disappears, but re-disapear when I restart the app.
I'm using AppCompat v22 support lib and my Activity is AppCompat Activity.
I override this function in MainAcitivity:
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if(hasFocus){
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
// translucent status bar
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// translucent navigation bar
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}
}
}
In MainAcitvity there's only a fragment :
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="#+id/main_fragment"
android:name="org.bitoo.abit.ui.MainActivityFragment"
tools:layout="#layout/fragment_mission_list" android:layout_width="match_parent"
android:layout_height="match_parent" />
and the layout of fragment is here:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:materialdesign="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/light_primary_color"
tools:context="org.bitoo.abit.ui.DetailedMissionActivityFragment">
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_mission_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"/>
<com.gc.materialdesign.views.ButtonFloat
android:id="#+id/bt_add"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="15dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:background="#color/accent_color"
materialdesign:animate="false"
materialdesign:iconDrawable="#drawable/ic_action_new" />
</RelativeLayout>
Style of theme :
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">#style/my_actionbar_style</item>
<item name="colorPrimary">#color/primary_color</item>
<item name="colorPrimaryDark">#color/dark_primary_color</item>
</style>
<style name="my_actionbar_style" parent="Widget.AppCompat.ActionBar">
<item name="background">#color/dark_primary_color</item>
<item name="backgroundStacked">#color/dark_primary_color</item>
<item name="backgroundSplit">#color/dark_primary_color</item>
<item name="titleTextStyle">#style/my_actionbar_text_style</item>
</style>
<style name="my_actionbar_text_style" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/title_text_color</item>
</style>

Styling ActionMode ActionBar in Android 5.0 Lollipop (with AppCompat)

I used this tutorial to facelift my Holo app for Lollipop:
http://android-developers.blogspot.ru/2014/10/appcompat-v21-material-design-for-pre.html
What I have:
Theme
<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionModeOverlay">true</item>
<item name="colorPrimary">#color/theme_primary</item>
<item name="colorPrimaryDark">#color/theme_primary_dark</item>
<item name="colorAccent">#color/theme_accent</item>
</style>
Toolbar layout
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
Activity inherited from ActionBarActivity with a ListFragment fragment in the multi-choice mode
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
Result: The toolbar is OK. It uses the sepcified theme colors, but the ActionBar used by the ListFragment in the ActionMode (activated by tap-and-hold a list item) has the standard Dark.ActionBar colors. Also the popup menu of the action bar uses the dark theme.
I tried all the SO tricks, but still cannot solve that. I will appreciate any help.
BTW. I found that the dark colors of the ActionBar are caused by the toolbar's app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar", but have no idea how solve this, because this attribute is needed for the correct toolbar appearance.
Just add these two lines to the theme:
<item name="actionModeBackground">#color/theme_primary_dark</item>
<item name="actionBarPopupTheme">#style/ThemeOverlay.AppCompat.Light</item>
This might also be helpful in addition to #Andrey Shcherbakov's answer if you want to have more control of each individual color.
<!-- action bar title text color, icon color (ie: back icon, icons when editing text)-->
<item name="android:textColorPrimary">#FFFF00</item>
<!-- action bar background color-->
<item name="android:colorBackground">#444400</item>
<!-- color of line under contextual action bar-->
<item name="colorControlActivated">#00CC00</item>

Categories

Resources