I want to display navigation indicator for a drawer like in this image:
For some reason the indicator does not display. I spent many hours on google and SO and no solution worked for me.
Manifest:
android:theme="@style/Theme.AppCompat.Light"
Gradle:
compile 'com.android.support:appcompat-v7:23.1.1'
Layout (without parent):
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:id="@+id/puzzleScreen"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context=".activities.PuzzleActivity">
<lelisoft.com.lelimath.view.TilesView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tiles"/>
</LinearLayout>
<ListView
android:id="@+id/navList"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#ffeeeeee"/>
</android.support.v4.widget.DrawerLayout>
Activity:
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
public class PuzzleActivity extends AppCompatActivity {
protected void onCreate(Bundle state) {
super.onCreate(state);
mDrawerList = (ListView)findViewById(R.id.navList);
mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
mActivityTitle = getTitle().toString();
addDrawerItems();
setupDrawer();
private void setupDrawer() {
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) {
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
getSupportActionBar().setTitle("Navigation!");
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
getSupportActionBar().setTitle(mActivityTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
};
// getSupportActionBar().setHomeButtonEnabled(true);
// getSupportActionBar().setDisplayShowHomeEnabled(true);
mDrawerToggle.syncState();
mDrawerToggle.setDrawerIndicatorEnabled(true);
mDrawerLayout.setDrawerListener(mDrawerToggle);
}
private void addDrawerItems() {
String[] osArray = { "Android", "iOS", "Windows", "OS X", "Linux" };
mAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, osArray);
mDrawerList.setAdapter(mAdapter);
mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(PuzzleActivity.this, "Time for an upgrade!", Toast.LENGTH_SHORT).show();
}
});
}
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
Where is the issue? I tried Nexus 4 with Android 5 and Nexus 5x with Android 6.
UPDATE:
I have downloaded Android navigation drawer sample, it displayed the drawer in the second activity. Then I copied relevant parts to main activity - and the indicator disappeared. So it seems to be related that my activity has no parent.