Я пытаюсь настроить следующие параметры в моем приложении:AppCompat панель инструментов не показаны с панели навигации
- Toolbar (AppCompat v7 версия)
- Navigation Выдвижные
- Пред- Lollipop AppCompat v7 Материал темы
Я следовал инструкции здесь: http://android-developers.blogspot.com/2014/10/appcompat-v21-material-design-for-pre.html
Однако после объявления .NoActionBar в теме, а также размещения панели инструментов в макете, моя панель инструментов не показывает. То, что я получаю, - это именно то, что вы ожидали бы при объявлении ни одной панели действий - никакой панели действий. Вот раскладка:
<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"
android:orientation="vertical"
tools:context=".MainActivity">
<!-- Toolbar -->
<include layout="@layout/toolbar"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout_main"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<Spinner
android:id="@+id/spinner_main"
android:visibility="gone"
android:textAlignment="center"
android:gravity="center"
android:layout_gravity="center_horizontal"
android:entries="@array/error_loading_content_array"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@+id/container"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0px"></FrameLayout>
</LinearLayout>
<fragment
android:id="@+id/navigation_drawer"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:name=".NavigationDrawerFragment"
tools:layout="@layout/fragment_navigation_drawer"/>
Toolbar.xml:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
В MainActivity.java:
// Load view/layout
setContentView(R.layout.guidelib_activity_main);
// TODO: Toolbar not showing
mToolbar = (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
Решение
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linearlayout_root_main"
android:layout_width="match_parent"
android:layout_height="match_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"
tools:context=".MainActivity">
<LinearLayout
android:id="@+id/layout_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- Toolbar -->
<!-- Moved up to new LinearLayout root tag -->
<!--<include layout="@layout/toolbar"/>-->
...
Как выглядит этот стиль '' @ style/ThemeOverlay.AppCompat.Dark.ActionBar "' – tyczj
@tyczj Это стиль, предоставляемый Android. ''. Даже если я изменю тему, она по-прежнему не отображает мою панель инструментов. – user1234
Вы не должны использовать какую-либо тему, которая говорит actionbar, потому что нет панели действий – tyczj