I am trying to open the Android sample project - Navigation Drawer in Android Studio, but got error while building it.
These are the steps to reproduce it:
The compiler cannot find this attribute in the activity_navigation_drawer.xml
:
app:layoutManager="LinearLayoutManager"
To fix this
Remove this attribute from the XML so your Recyclerview looks like this:
press the Gradle Sync button
In NavigationDrawerActivity
, add the following 2 lines of code in your OnCreate();
LinearLayoutManager mLinearLayoutmanager = new LinearLayoutManager(this);
mDrawerList.setLayoutManager(mLinearLayoutmanager);
So your code now looks like this:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_navigation_drawer);
mTitle = mDrawerTitle = getTitle();
mPlanetTitles = getResources().getStringArray(R.array.planets_array);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (RecyclerView) findViewById(R.id.left_drawer);
LinearLayoutManager mLinearLayoutmanager = new LinearLayoutManager(this);
mDrawerList.setLayoutManager(mLinearLayoutmanager);
....
Good luck
Edit:
The reason why this the original xml code is no longer working, is most likely that the xmlns:app="http://schemas.android.com/apk/res-auto"
namespace is no longer supporting the layoutManager
attribute.
More info on the namespace can be found here: https://stackoverflow.com/a/26692768/3708094