Issue
I am looking to implement a navigation drawer selector which shows the currently selected item at all times when the drawer is opened and that is retained even when the drawer is closed. Something like this:
I have used something like this but it only shows the selector when I click on the list item. This is in my res folder:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/list_activated_holo" />
</selector>
How do i attain the above shown implementation?Which state do i need to implement? Thanks
Solution
Have resolved same issue by setting color in getView() of ArrayAdapter that populates my list in NavigationDrawer:
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = LayoutInflater.from(getActivity()).inflate(
R.layout.side_menu_list_item,
parent,
false);
holder = new ViewHolder();
holder.title = (TextView) convertView.findViewById(R.id.text1);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
if (mCurrentSelectedPosition == position) {
holder.title.setBackgroundResource(R.color.menu_list_separator_line);
} else {
holder.title.setBackgroundResource(R.color.app_background_light);
}
holder.title.setText(menuItems[position]);
return convertView;
}
Answered By - vsvydenko
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.