I need to show the background colour white colour in slider menu

547 Views Asked by At

enter image description here I am using NavigationDrawerItemsAdapter listener for showing the options in slider menu when option are less it is showing half part as transparency i want to show white background as height of the device.

    public class BaseNavigationDrawerActivity extends BaseActivity implements



        // for getting Left Navigation drawerImages

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_navigation_screen);

            mContext = BaseNavigationDrawerActivity.this;
            mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
            mDrawersList = (ListView) findViewById(R.id.lv_left_drawer);

            LayoutInflater inflater = this.getLayoutInflater();

            // adding listview header
            View header = inflater.inflate(R.layout.leftnav_headerview, null);
            mDrawersList.addHeaderView(header);
            mProfileView = (ImageView) header.findViewById(R.id.img_profile);
            mProfileUserName = (TextView) header.findViewById(R.id.tv_username);
            // set a custom shadow that overlays the main content when the drawer
            // opens
            ShowLogoutOption();

            mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
                    GravityCompat.START);

            mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
                    R.drawable.ic_apphistory_menu, R.string.drawer_open,
                    R.string.drawer_close) {
                @Override
                public void onDrawerClosed(View drawerView) {
                    supportInvalidateOptionsMenu();
                }

                @Override
                public void onDrawerOpened(View drawerView) {
                    supportInvalidateOptionsMenu();
                }
            };

            mNavigationDrawerAdapter = new NavigationDrawerItemsAdapter();
            mDrawersList.setAdapter(mNavigationDrawerAdapter);
            mDrawerLayout.setDrawerListener(mDrawerToggle);
            mProfileUserName.setEnabled(false);
            mDrawersList.setOnItemClickListener(new DrawerItemClickListener());
            mProfileView.setOnClickListener(this);
            initActionBar("",false);
        }

        @Override
        protected void onResume() {
            super.onResume();

            mNavigationDrawerAdapter.notifyDataSetChanged();
        }



        @Override
        protected void onPostCreate(Bundle savedInstanceState) {
            super.onPostCreate(savedInstanceState);
            // Sync the toggle state after onRestoreInstanceState has occurred.
            mDrawerToggle.syncState();
        }

        @Override
        public void onConfigurationChanged(Configuration newConfig) {
            super.onConfigurationChanged(newConfig);
            // Pass any configuration change to the drawer toggls
            mDrawerToggle.onConfigurationChanged(newConfig);
        }

        private class DrawerItemClickListener implements OnItemClickListener {
            @Override
            public void onItemClick(AdapterView<?> parent, View v, int position,
                    long arg3) {
                mDrawersList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);



            }


        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            return super.onCreateOptionsMenu(menu);
        }

        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            if (mDrawerToggle.onOptionsItemSelected(item)) {
                return true;
            }
            return super.onOptionsItemSelected(item);
        }

        protected void replaceFragment(Fragment fragment) {
            FragmentManager fragmentManager = getSupportFragmentManager();
            fragmentManager.beginTransaction()
                    .replace(R.id.content_frame, fragment).commit();
        }

        /**
         * This class used to update data to LeftNavigationDrawer
         * 
         * @author nvanamala
         * 
         */
        private class NavigationDrawerItemsAdapter extends BaseAdapter {
            private ImageView mLeftNavigationImage;
            private TextView mLeftNavigationText;

            @Override
            public int getCount() {
                return mLeftNavigationDrawerItems.length > 0 ? mLeftNavigationDrawerItems.length
                        : 0;
            }

            @Override
            public Object getItem(int position) {
                return position;
            }

            @Override
            public long getItemId(int position) {
                return position;
            }

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


                if (convertView == null) {
                    LayoutInflater inflater = (LayoutInflater) mContext
                            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    convertView = inflater.inflate(R.layout.left_navigation_row,
                            null, false);
                }
                mLeftNavigationText = (TextView) convertView.findViewById(R.id.tv_left_nav_title);
                mLeftNavigationImage = (ImageView) convertView.findViewById(R.id.img_left_nav);

                mLeftNavigationText.setText(mLeftNavigationDrawerItems[position]);

                // If the position is RewardPoints then add the points to reward point
                    if (mLeftNavigationText.getText().toString().trim().equalsIgnoreCase(mRewardPoints)) {


                }

                }

                convertView.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {

                        String item = mLeftNavigationDrawerItems[position];

                        selectItem(item);
                    }
                });

    //          mLeftNavMenuImages.recycle();
                return convertView;
            }

        }



    }
![enter image description here][1]


  [1]: https://i.stack.imgur.com/iSXRR.png
2

There are 2 best solutions below

0
On

set findViewById(R.id.lv_left_drawer); this view to FILL_PARENT or MATCH_PARENT in the xml. If it a linearlayout or a relativelayout with a listview inside, then set the background color of the main view, the root view to white

using

@android:color/white
0
On

The DrawerLayout height should be fill or match parent then you can change it programmatically

      mDrawerLayout.setBackgroundColor(Color.WHITE);

hope this will help.