Highlight Selected item in menu / popup menu

Used library:

Question:

I am trying to implement highlighting on menudrawer, similar to the YouTube / Beautiful Widget application, but I do not know how this should approach the problem.

below I give a sample to my aprproche, which I am not sure if its the correct way to implement something like this:

This is the menu box Adaptervew.click lisner I created:

 private AdapterView.OnItemClickListener mItemClickListener = new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position,
                    long id) {

            mPreviousView=mActiveView;
            mActiveView=view;
            mActivePosition = position;
         //   mDrawer.setActiveView(view, position);
            TextView txtview=(TextView)mActiveView;
            txtview.setBackgroundResource( R.drawable.abs__cab_background_top_holo_dark);
           // mDrawer.closeMenu();
        }
    };

So basically I'm trying to use .9 image here in the currently selected view!

What I want to know is a more systematic or better approach to do the same!

What I want to achieve screenshots below:

enter image description hereenter image description here

+5
3

:

public View getView(int position, View convertView, ViewGroup parent) {
    view.setSelectionHandlerColorResource(Set your color here);
}
0

, :

1) drawerPosition NavDrawer:

public class NavDrawerBaseActivity extends Activity {

    public static int LAST_DISPLAY_POSITION = 0;

    private void displayView(int position) {
        LAST_DISPLAY_POSITION = position;

        Fragment fragment = null;
        switch (position) {
            case 0:
                fragment = new ProgressPageFragment();
                break;
            // ..

            default:
                break;
        }

        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();

        // .. update selected item and title, then close the drawer
    }

2, , :

public class NavDrawerListAdapter extends BaseAdapter {
   // ..

    @Override
    public View getView(int position, View convertView, ViewGroup parent {

        TextView txtTitle = (TextView) convertView.findViewById(R.id.title);

        if (position == NavDrawerActivity.LAST_DISPLAY_POSITION) {
            txtTitle.setTextColor(Color.WHITE);
        }
        else
           txtTitle.setTextColor(Color.BLACK);

        // .. etc ..
+2

There would be several ways to solve this problem. My favorite approach would be to place a ListView TextView element inside a FrameLayout. In this case, FrameLayout may have a front panel with the output of your indicator. You can show / hide this indicator programmatically or using the selector.

0
source

All Articles