Android change background color of popup menu - android

I don't understand why is so painful to change a color for an android app.
I tried several ways to change the background color of the popup menu in my action bar with no success.
I'm using a AppTheme.NoActionBar to style, obviously, the action bar.
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="navigationIcon">#drawable/ic_return_dark</item>
<item name="overlapAnchor">false</item>
<item name="popupMenuStyle">#style/PopupMenu</item>
</style>
<style name="PopupMenu" parent="Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">#color/color4</item>
</style>
Following the examples that I found, there was this explanation that you need to insert in your custom style (in my case AppTheme.NoActionBar) a custom popupMenuStyle in order to custom the popupBackground, which changes the background color of popup menu.
It doesn't work.
What can I do to change the background color of popup menu?

To change the color of the Options Menu in Android, changing themes and styles won't help. You have to initialise LayoutInflater Factory Class.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.my_menu, menu);
getLayoutInflater().setFactory(new Factory() {
#Override
public View onCreateView(String name, Context context,
AttributeSet attrs) {
if (name .equalsIgnoreCase(“com.android.internal.view.menu.IconMenuItemView”)) {
try {
LayoutInflater f = getLayoutInflater();
final View view = f.createView(name, null, attrs);
new Handler().post(new Runnable() {
public void run() {
view.setBackgroundResource(R.drawable.your_color);
((TextView) view).setTextColor(Color.your_color);
}
});
return view;
} catch (InflateException e) {
} catch (ClassNotFoundException e) {
}
}
return null;
}
});
return super.onCreateOptionsMenu(menu);
}

If someone is still wondering is there is a better solution to this problem, here's the explanation and answer.
Since, the question clearly mentions using NoActionBar theme for app, setting popupMenu directly to AppTheme will not work.
Instead you need to apply that theme manually to your toolbar in xml
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="#style/PopupMenu" />
and in your styles.xml file
<style name="PopupMenu" parent="Theme.AppCompat.Light">
<item name="android:textColor">#color/white</item>
<item name="android:colorBackground">#color/popup_color</item>
</style>

Related

Style dialog after click on MediaRouteButton

Hi can someone help me with styling dialog that appears after clicking on MediaRouteButton?
There is a white text displayed on gray background which doesn't look good.
android.support.v7.app.MediaRouteButton
is wrapped in parent with styles
<FrameLayout
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:fitsSystemWindows="true"
app:popupTheme="#style/ThemeOverlay.AppCompat.Dark"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
(I know that I should use Toolbar here but it doesn't match my requirements)
which works good on MediaRouteButton which turns white, but it have no influence on dialog styles.
I tried to look at sample app provided by Google, but I haven't found anything that helps me. Link to sample app styles
My current theme:
<style name="Theme.AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>//Blue
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>//dark blue
<item name="colorAccent">#color/colorPrimary</item>//blue
</style>
Found a solution that worked for me.
At first you have to set a custom MediaRouteDialogFactory on your MediaRouteButton
mMediaRouteMenuItem = CastButtonFactory.setUpMediaRouteButton(this, menu, R.id.media_route_menu_item);
MediaRouteButton mediaRouteButton = (MediaRouteButton) mMediaRouteMenuItem.getActionView()
mediaRouteButton.setDialogFactory(new ThemeableMediaRouteDialogFactory());
Cause the default MediaRouteDialogFactory will always create non themed Dialogs
#NonNull
public MediaRouteControllerDialogFragment onCreateControllerDialogFragment() {
return new MediaRouteControllerDialogFragment();
}
which will lead to
public MediaRouteControllerDialog onCreateControllerDialog(
Context context, Bundle savedInstanceState) {
return new MediaRouteControllerDialog(context);
}
but there is also a themed constructor MediaRouteControllerDialog(Context context, int theme)
which is not called from original MediaRouteDialogFactory.
So your ThemeableMediaRouteDialogFactory should be look like this
public class ThemeableMediaRouteDialogFactory extends MediaRouteDialogFactory {
#NonNull
#Override
public MediaRouteChooserDialogFragment onCreateChooserDialogFragment() {
return new ThemeableMediaRouterChooserDialogFragment();
}
#NonNull
#Override
public MediaRouteControllerDialogFragment onCreateControllerDialogFragment() {
return new ThemeableMediaRouteControllerDialogFragment();
}
}
with
public class ThemeableMediaRouterChooserDialogFragment extends MediaRouteChooserDialogFragment {
#Override
public MediaRouteChooserDialog onCreateChooserDialog(Context context, Bundle savedInstanceState) {
return new MediaRouteChooserDialog(context, R.style.CastChooserDialogTheme);
}
}
and
public class ThemeableMediaRouteControllerDialogFragment extends MediaRouteControllerDialogFragment {
#Override
public MediaRouteControllerDialog onCreateControllerDialog(Context context, Bundle savedInstanceState) {
return new MediaRouteControllerDialog(context, R.style.CastControllerDialogTheme);
}
}
Your themes/styles can also be customized
<style name="DarkDialogTheme" parent="Theme.AppCompat.Dialog">
<item name="colorPrimary">#color/charcoal_grey</item>
<item name="colorPrimaryDark">#color/charcoal_grey_dark</item>
<item name="colorAccent">#color/pumpkin_orange</item>
<item name="android:windowBackground">#color/dark_grey</item>
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:windowNoTitle">true</item>
</style>
<style name="CastChooserDialogTheme" parent="DarkDialogTheme">
<item name="android:windowNoTitle">false</item>
<item name="mediaRouteChooserPrimaryTextStyle">#style/MediaRouteChooserPrimaryText</item>
<item name="mediaRouteChooserSecondaryTextStyle">#style/MediaRouteChooserSecondaryText</item>
</style>
<style name="CastControllerDialogTheme" parent="DarkDialogTheme">
<item name="MediaRouteControllerWindowBackground">#color/dark_grey</item>
<item name="colorPrimary">#color/dark_grey</item>
<item name="mediaRouteCloseDrawable">#drawable/ic_dialog_close_dark</item>
<item name="mediaRouteControllerTitleTextStyle">#style/Widget.MediaRouter.ControllerText.Title.Dark</item>
</style>

Not able to set action bar background color and selected listview color

i have used the following code:
listview.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
#Override
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
final int checkedCount = listview.getCheckedItemCount();
mode.setTitle(checkedCount + " Selected");
}
#Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mode.getMenuInflater().inflate(R.menu.mymenu, menu);
return true;
}
#Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
#Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
switch (item.getItemId()) {
case R.id.delete:
//my delete code
mode.finish();
return true;
default:
return false;
}
}
#Override
public void onDestroyActionMode(ActionMode mode) {
//
}
});
mymenu.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/delete"
android:icon="#android:drawable/ic_menu_delete"
android:title="Delete"
app:showAsAction="always"
/>
</menu>
styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:actionModeBackground">#android:color/holo_blue_dark</item>
<item name="android:actionModeStyle">#style/TestActionModeStyle</item>
</style>
<style name="TestActionModeStyle">
<item name="android:titleTextStyle">#style/TestTitleStyle</item>
<item name="android:subtitleTextStyle">#style/TestSubTitleStyle</item>
</style>
<style name="TestTitleStyle">
<item name="android:textColor">#android:color/black</item>
<item name="android:background">#android:color/holo_red_dark</item>
</style>
<style name="TestSubTitleStyle">
<item name="android:textColor">#android:color/black</item>
<item name="android:background">#android:color/holo_green_dark</item>
</style>
When i longpress on listview then item is selected and menu is coming with delete button. But i am not able to set the color of that whole menu and event the selected listview item is also not reflected.
Menu background color occus in white and selected listview item is also occurs white color.
So i want to change the menu color and selected item from listview color.
From above code it is not working.
How can i solved this?
Check this answer for your menu part of the question: How to change the background color of Action Bar's Option Menu in Android 4.2?
And this answer Change background color of selected item on a ListView, for changing your selected listview item.
Just for completeness here the parts of those questions that are relevant for you:
For the menu (note they speak about the Actionbar, but the menu is also included):
There is an easy way to change the colors in Actionbar Use ActionBar
Generator..
but since you already have a style you only want to update the menu like a bit further in the linked question:
In the style generator, the relevant setting is Popup color, which
affects "Overflow menu, submenu and spinner panel background".
Go on and generate the zip, but out of all the files generated, you
only really need one image, menu_dropdown_panel_example.9.png, which
looks something like this:
So, add the different resolution versions of it to res/drawable-*.
(And perhaps rename them to menu_dropdown_panel.9.png.)
Then, as an example, in res/values/themes.xml you would have the
following, with android:popupMenuStyle and android:popupBackground
being the key settings.
<style name="MyAppActionBarTheme" parent="android:Theme.Holo.Light">
<item name="android:popupMenuStyle">#style/MyApp.PopupMenu</item>
<item name="android:actionBarStyle">#style/MyApp.ActionBar</item>
</style>
<!-- The beef: background color for Action Bar overflow menu -->
<style name="MyApp.PopupMenu" parent="android:Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">#drawable/menu_dropdown_panel</item>
</style>
<!-- Bonus: if you want to style whole Action Bar, not just the menu -->
<style name="MyApp.ActionBar" parent="android:Widget.Holo.Light.ActionBar.Solid">
<!-- Blue background color & black bottom border -->
<item name="android:background">#drawable/blue_action_bar_background</item>
</style>
For the listview:
You can keep track the position of the current selected element:
OnItemClickListener listViewOnItemClick = new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapter, View arg1, int position, long id) {
mSelectedItem = position;
mAdapter.notifyDataSetChanged();
}
};
And override the getView method of your adapter:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
final View view = View.inflate(context, R.layout.item_list, null);
if (position == mSelectedItem) {
// set your color
}
return view;
}

How to add an customized button on the actionbar?

I want to make an action bar with a button on the right with a margin_right. like this
And I use the action button to do it. But the button was on the right without margin_right.
android:layout_marginRight doesn't work here.
here is my styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarSize">50dp</item>
<item name="android:actionBarStyle">#style/my_actionbar_style</item>
<item name="android:actionButtonStyle">#style/my_action_button</item>
</style>
<style name="my_actionbar_style" parent="android:Widget.ActionBar">
<item name="android:background">#color/actionbar_backgroud</item>
<item name="android:titleTextStyle">#style/myTitleStyle</item>
<item name="android:displayOptions">showTitle</item>
</style>
<style name="myTitleStyle">
<item name="android:textColor">#ffffff</item>
<item name="android:textSize">20sp</item>
</style>
<style name="my_action_button">
<item name="android:background">#drawable/button_selector</item>
<item name="android:width">70dp</item>
<item name="android:textSize">13sp</item>
<item name="android:layout_marginTop">10dp</item>
<item name="android:layout_marginBottom">10dp</item>
<item name="android:layout_marginRight">10dp</item>
</style>
and this is my menu.xml:
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:ignore="AppCompatResource">
<item
android:id="#+id/action_search"
android:title="submit"
android:showAsAction="always" /></menu>
Another quick and clean way to go about this is specifying your own layout for that menu button. something like this
<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="com.example.MainActivity">
<item
android:id="#+id/action_custom_button"
android:title="Custom Button"
android:icon="#drawable/ic_custom_button"
app:actionLayout="#layout/layout_to_custom_button"
app:showAsAction="always" />
</menu>
there should be
layout_to_custom_button.xml
layout file which contains the padding and style you wanted.
and also do this in your activity for the click event
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_product_detail, menu);
final Menu mMenu = menu;
final MenuItem item = menu.findItem(R.id.action_custom_button);
item.getActionView().setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
mMenu.performIdentifierAction(item.getItemId(), 0);
}
});
return true;
}
I found the easiest way to do this was to just create your own action bar in a layout file. You can then use it by having your activities inherit from a common activity that overrides setContentView, where you just stick the view you're given into a parent view containing that and your action bar. You can mimick the overflowing menu behavior by using ActionMenuView (5.0+).
For example, assume you have an action_bar.xml with an ActionMenuView in it named menuView:
class BaseActivity extends Activity {
...
ActionMenuView mMenuView;
...
#Override
protected void setContentView(int resId) {
LayoutInflater inflater = getLayoutInflater();
View actionBar = inflater.inflate(R.layout.action_bar, null);
View contentView = inflater.inflate(resId);
mMenuView = (ActionMenuView)actionBar.findViewById(R.id.menuView);
RelativeLayout parentLayout = new RelativeLayout(this);
LayoutParams actionBarLayout = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
actionBar.setLayoutParams(actionBarLayout);
parentLayout.addView(actionBar);
actionBar.setId(R.id.actionBar);
LayoutParams contentLayout = new LayoutParams(LayoutParams.MATCH_PARENT, 0);
contentLayout.addRule(RelativeLayout.BELOW, actionBar.getId());
contentLayout.addRule(RelativeLayout.ALIGN_WITH_PARENT_BOTTOM);
contentView.setLayoutParams(contentLayout);
parentLayout.addView(contentView);
setContentView(parentLayout);
}
}

search view with back icon in android

In my project I am using search view of android.
It is working properly.
But I am having one problem i.e related to back image while searchview expands.
This is my action bar with icon and other search and drawable icon.
Now when I click on search Icon
Here Icon is changes. It's by default taking launcher image. but I want it to be same as its showing in image 1.
So can any one help me with this issue.
edit1
here is my action bar style xml.
<style name="Theme.Example" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarItemBackground">#drawable/selectable_background_example</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle.Example</item>
<item name="actionBarStyle">#style/ActionBar.Solid.Example</item>
<item name="actionModeBackground">#drawable/cab_background_top_example</item>
<item name="actionModeSplitBackground">#drawable/cab_background_bottom_example</item>
<item name="actionBarTabTextStyle">#style/ActionBarTabText.Example</item>
<!-- Light.DarkActionBar specific -->
<item name="android:textColorHighlight">#99c0c0c0</item>
</style>
edit2
substyle for actionbar
<style name="ActionBar.Solid.Example" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:icon">#drawable/ic_logo</item>
<item name="background">#drawable/ab_solid_example</item>
<item name="backgroundStacked">#drawable/ab_stacked_solid_example</item>
<item name="backgroundSplit">#drawable/ab_bottom_solid_example</item>
</style>
edit 3
This is my onCreateOptionsMenu method.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
try {
search = (MenuItem) menu.findItem(R.id.search);
MenuItemCompat.setOnActionExpandListener(search,
new OnActionExpandListener() {
#Override
public boolean onMenuItemActionCollapse(MenuItem item) {
// Do something when collapsed
layoutList.setVisibility(View.INVISIBLE);
return true; // Return true to collapse action view
}
#Override
public boolean onMenuItemActionExpand(MenuItem item) {
// Do something when expanded
layoutList.setVisibility(View.VISIBLE);
return true; // Return true to expand action view
}
});
SearchView searchView = (SearchView) MenuItemCompat
.getActionView(search);
setSearchTextColour(searchView);
searchView.setQueryHint(getString(R.string.search_hint));
searchView.setOnQueryTextListener(this);
searchView.setOnCloseListener(new OnCloseListener() {
#Override
public boolean onClose() {
// TODO Auto-generated method stub
Debugger.debugE("on close");
layoutList.setVisibility(View.INVISIBLE);
return false;
}
});
} catch (Exception e) {
// TODO: handle exception
}
return super.onCreateOptionsMenu(menu);
}
and to show actionbar
ActionBar actionBar = getSupportActionBar();
SpannableString s = new SpannableString(getString(R.string.app_name));
s.setSpan(new TypeFaceSpan(getContext(),
getString(R.string.font_gothum)), 0, s.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
actionBar.setTitle(s);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setBackgroundDrawable(new ColorDrawable(Color
.parseColor("#bb0404")));
There is nothing else that I had used.
note: In all other navigation from the main screen icon which is showing in first image is coming.
Issue is only with searchview.
Thanks in advance.
Bskania
Try changing your app theme on your styles.xml
You can do something like this:
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/ActionBar</item>
</style>
<style name="ActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:icon">#drawable/myicon</item>
</style>
create a custom action bar :
LayoutInflater inflator = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.custom_search_actionbar, null);
actionBar.setCustomView(v);
_searchView = (SearchView)v.findViewById(R.id.searchView);
....
....
....
and define ids of views and use .

Can't change the text color with Android Action Bar drop-down navigation

I'm using Drop-down Navigation with my Action bar, and I can't get a sensible color for the corresponding text when using a dark action bar. The action bar itself is a dark grey, and the text color is black, so it's very hard to read.
I followed the basic instructions on the Action Bar developer's guide so my code is simply
SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.action_list, android.R.layout.simple_spinner_dropdown_item);
ActionBar.OnNavigationListener navigationListener = new OnNavigationListener() {
#Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
// TODO
return false;
}
};
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
actionBar.setListNavigationCallbacks(mSpinnerAdapter, navigationListener);
and my styles.xml was simply
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
</style>
</resources>
I think that should have given me something sensible, but as the following image shows, it comes out as black text on a dark grey background so it's no good.
I've tried playing around with the styles.xml file to try and solve the problem. My best attempt was the following
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionDropDownStyle">#style/myActionDropDownStyle</item>
<item name="android:actionBarStyle">#style/myActionBar</item>
</style>
<style name="myActionDropDownStyle" parent="android:style/Widget.Holo.Light.Spinner">
<item name="android:background">#color/LightCyan</item>
</style>
<style name="myActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:titleTextStyle">#style/myActionBar.titleTextStyle</item>
</style>
<style name="myActionBar.titleTextStyle" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title.Inverse">
<item name="android:textColor">#color/Orange</item>
</style>
</resources>
which was (1) able to change the text color of the app title to Orange, (2) able to change the background color of the selected navigation item in the action bar to a light blue, (3) able to change the background color of the dropdown so that at least the black text is shown against a light background. However nothing I do changes the text color itself, either for the selected item shown in the action bar, or for the items shown in the dropdown. My best attempt also looks horrible :-(!
All I want is a dark action bar with a sensible text color for the selected item shown in the action bar, which should be the same text color used when an item is being selected, and with the background color for the dropdown when an item is being selected being the same color as the action bar. But I can't work out how to do it, can anyone help?
FYI, I'm using Eclipse with an adt-bundle that I downloaded very recently (adt-bundle-windows-x86_64-20130219). When I search for solutions, I find a lot about the Sherlock action bar, however the styles for Sherlock weren't included in that adt-bundle. In any case, surely what I want should be possible with the Holo.Light.DarkActionBar that I'm using?
Please forgive my necromancy but this really bugged me today and the solution is actually quite quick and requires no custom adapters or styling.
If you change the context in the SpinnerAdapter's constructor to use getActionBar().getThemedContext() rather than this it will show light text on a dark background that will match the Action Bar's style.
SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(getActionBar().getThemedContext(), R.array.action_list, android.R.layout.simple_spinner_dropdown_item);
I've worked out that I can alter the colors for the drop-down Navigation in code, by creating my own subclass of ArrayAdapter as follows:
public class myArrayAdaptor<T> extends ArrayAdapter<T> {
public myArrayAdaptor(Context context, int textViewResourceId, T[] objects) {
super(context, textViewResourceId, objects);
}
public static myArrayAdaptor<CharSequence> createFromResource(Context context, int textArrayResId, int textViewResId) {
CharSequence[] strings = context.getResources().getTextArray(textArrayResId);
return new myArrayAdaptor<CharSequence>(context, textViewResId, strings);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
return SetColourWhite(super.getView(position, convertView, parent));
}
#Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
return SetColourWhite(super.getView(position, convertView, parent));
}
private View SetColourWhite(View v) {
if (v instanceof TextView) ((TextView)v).setTextColor(Color.rgb(0xff, 0xff, 0xff)); // white
return v;
}
}
Then with the simple styles.xml
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
</style>
</resources>
I can substitute the class myArrayAdaptor
SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.action_list, android.R.layout.simple_spinner_dropdown_item)
and the text color will always be white. But isn't there a simpler way of doing this using settings in the styles.xml file?
Java code
SpinnerAdapter adapter = ArrayAdapter.createFromResource(this,
R.array.actions,R.layout.dropdown_textcolor);
// OnNavigationListener
OnNavigationListener callback = new OnNavigationListener() {
String[] items = getResources().getStringArray(R.array.actions);
public boolean onNavigationItemSelected(int position, long id) {
// Do stuff when navigation item is selected
Log.d("NavigationItemSelected", items[position]); // Debug
return true;
}
};
ActionBar actions = getSupportActionBar();
actions.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
actions.setDisplayShowTitleEnabled(false);
actions.setListNavigationCallbacks(adapter, callback);
Xml dropdown_textcolor.xml
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
style="?android:attr/spinnerDropDownItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:textColor="#android:color/white"
android:layout_height="wrap_content"
android:padding="10dp"
android:ellipsize="marquee"
android:textAlignment="inherit"/>
Add this in your styles.xml that will change the color of your hidden action menu text:
<style name="AppTheme.AppCompat.Light" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:itemTextAppearance">#style/MenuTextAppearance</item>
</style>
<style name="MenuTextAppearance">
<item name="android:textColor">#android:color/black</item>
</style>
<resources>
<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>
<!-- Customize your theme here. -->
<item name="android:textColor">#ffffff</item>
<item name="android:itemBackground">#991005</item>
<item name="android:actionBarSize">40dp</item>
<item name="android:divider">#ff0000</item>
<item name="android:dividerHeight">1dp</item>
<item name="android:textSize">14sp</item>
</style>
</resources>
If you are using AppCompat support library .. this might help you..
<style name="MyActionBar3" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="android:background">#color/ActionBarBackground</item>
</style>
<style name="MyActionBarDropDownStyle" parent="">
<item name="android:background">#00FF00</item>
<item name="android:divider">#ff0000</item>
<item name="android:dividerHeight">1dp</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:textSize">10sp</item>
</style>
<style name="MyTextStyle" parent="#style/Widget.AppCompat.Light.Base.ListPopupWindow">
<item name="android:popupBackground">#FF0000</item>
</style>

Categories

Resources