Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set custom color on selected/highlighted list-item in activatedBackgroundIndicator

Hello I am developing an app using ActionBarSherlock and Navigation Drawer. I have created an initial navigation drawer with actionBar Sherlock just like this:

activatedBackgroundIndicator

Everything seems okay But I want to change default blue color of highlighted list-item with my custom color. I tried this link but it is not working. What I need to do to achieve custom highlight color?

like image 544
Kaidul Avatar asked Jul 12 '13 21:07

Kaidul


1 Answers

Hello I have solved it for android OS version 11 and higher by applying style:

<style name="AppBaseTheme" parent="Theme.Sherlock.Light.DarkActionBar">
    <!-- API 14 theme customizations can go here. -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:activatedBackgroundIndicator">@drawable/activated_background</item>
</style>

activated_background in the drawable folder:

<selector xmlns:android="http://schemas.android.com/apk/res/android">  
   <item android:state_activated="true" android:drawable="@color/uva_color" />
   <item android:state_selected="true" android:drawable="@color/uva_color" />
   <item android:state_pressed="true" android:drawable="@color/uva_color" />
   <item android:drawable="@color/default_color" />  
</selector>

Color values in the values folder:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="uva_color">#c31756</color>
    <color name="default_color">#111</color>
</resources>

And set choicemode in the listview:

android:choiceMode="singleChoice"

And at last, send getBaseContext() to arrayApdater/your customAdapter as parameter instead of getApplicationContext().

mMenuAdapter = new MenuListAdapter(this.getBaseContext(), title, icon);

Also this link would help you.

Comment below if you face problem anywhere. I am ready to answer anytime, I don't want to let anyone getting trouble with this like me. Cheers!

like image 82
Kaidul Avatar answered Oct 04 '22 15:10

Kaidul