android - Not able to set action bar background color and selected listview color -
i have used 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 longpress on listview item selected , menu coming delete button. not able set color of whole menu , event selected listview item not reflected.
menu background color occus in white , selected listview item occurs white color.
so want change menu color , selected item listview color.
from above code not working.
how can solved this?
check answer menu part of question: how change background color of action bar's option menu in android 4.2?
and answer change background color of selected item on listview, changing selected listview item.
just completeness here parts of questions relevant you:
for menu (note speak actionbar, menu included):
there easy way change colors in actionbar use actionbar generator..
but since have style want update menu bit further in linked question:
in style generator, relevant setting popup color, affects "overflow menu, submenu , spinner panel background".
go on , generate zip, out of files generated, need 1 image, menu_dropdown_panel_example.9.png, looks this:
so, add different resolution versions of res/drawable-*. (and perhaps rename them menu_dropdown_panel.9.png.)
then, example, in res/values/themes.xml have following, android:popupmenustyle , android:popupbackground being 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> <!-- beef: background color 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 want style whole action bar, not 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 listview:
you can keep track position of 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 getview method of 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 color } return view; }
Comments
Post a Comment