Custom background color for selected item with “activatedBackgroundIndicator” Navigation Drawer

后端 未结 2 2083
囚心锁ツ
囚心锁ツ 2021-02-19 20:35

This question has been asked a lot on SO, and I have referenced all the answers. I am still left with the default Holo blue background for selected items on my navigation drawe

2条回答
  •  无人共我
    2021-02-19 20:58

    I wasn't able to find any full clear answer to this question, so here it is:

    Step 1. Specify the list item layout your adapter will use, in this example we're specifying:R.layout.fragment_navigation_drawer_list_item

    Like so:

    mDrawerListView.setAdapter(new ArrayAdapter(
            // First parameter - Context
            getActionBar().getThemedContext(),
            // Second parameter - Layout for the row
            R.layout.fragment_navigation_drawer_list_item,
            // Third parameter - ID of the TextView to which the data is written
            android.R.id.text1,
            // Forth - the Array of data
            new String[]{
                    getString(R.string.title_section1),
                    getString(R.string.title_section2),
                    getString(R.string.title_section3),
                    getString(R.string.title_section4),
            }))`
    

    Step 2. Create and customize fragment_navigation_drawer_list_item.xml to specify a drawable that will have a selector like so: android:background="@drawable/activated_background" Full example:

    
    

    Step 3. Create and customize the selector in your activated_background.xml file just like in the question, it will look like this:

    
        
        
        
        
        
    
    

提交回复
热议问题