我想显示如下图所示抽屉的导航指示器:
由于某种原因,指示器不显示。我在 google 和 SO 上花了很多时间,但没有任何解决方案对我有用。
显现:
android:theme="@style/Theme.AppCompat.Light"
摇篮:
compile 'com.android.support:appcompat-v7:23.1.1'
布局(无父):
<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>
活动:
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();
}
问题出在哪里?我尝试了使用 Android 5 的 Nexus 4 和使用 Android 6 的 Nexus 5x。
更新:
我已经下载了 Android 导航抽屉示例,它在第二个活动中显示了抽屉。然后我将相关部分复制到主要活动中 - 指示器消失了。因此,我的活动似乎没有父母。