Я пытаюсь реализовать панель инструментов с использованием библиотеки дизайна Android. Выход работает как ожидается на устройствах Lollipop и Marshmallow, но не показывает ToolBar на устройствах Kitkat.ActionBar не отображается на Android KitKat
Я видел аналогичные сообщения о переполнении стека (here_1, here_2) и попытался реализовать перечисленные изменения. Тем не менее, я не могу заставить эту работу работать с устройствами Kit Kat.
Я включил следующий в моем build.gradle файле:
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:cardview-v7:23.0.1'
Вот мой main_Activity.xml файл:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:theme="@style/Theme.MyMovie"
tools:context=".MainActivity">
<include layout="@layout/include_grid_viewpager"/>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header"
app:menu="@menu/drawer_view"/>
</android.support.v4.widget.DrawerLayout>
Вот мой include_grid_viewpager.xml файл:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Chalisa">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar1"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay"
/>
</android.support.design.widget.AppBarLayout>
<GridView
android:id="@+id/gridview1"
android:columnWidth="80dp"
android:paddingTop="?attr/actionBarSize"
android:gravity="center_horizontal"
android:background="@drawable/stroke"
android:numColumns="3"
android:stretchMode="spacingWidthUniform"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</GridView>
</android.support.design.widget.CoordinatorLayout>
и вот мой файл style.xml
<resources>
<style name="Theme.Mytheme" parent="Base.Theme.DesignDemo">
</style>
<style name="Base.Theme.DesignDemo" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#FF0000</item>
<item name="colorPrimaryDark">#FC1501</item>
<item name="colorAccent">#FF0000</item>
<item name="android:windowBackground">@color/window_background</item>
<item name="android:textSize">16sp</item>
</style>
<style name="Widget.CardContent" parent="android:Widget">
<item name="android:paddingLeft">16dp</item>
<item name="android:paddingRight">16dp</item>
<item name="android:paddingTop">24dp</item>
<item name="android:paddingBottom">24dp</item>
<item name="android:orientation">vertical</item>
</style>
</resources>
Вот мой файл манифеста:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="aps.com.nap" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Mytheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DetailData"
android:parentActivityName=".MainActivity"
android:screenOrientation="portrait"/>
<activity android:name=".myDetail"
android:parentActivityName=".MainActivity"
android:screenOrientation="portrait"/>
</application>
</manifest>
Я потратил более 4 часов копаться в Интернете и стека ответов на переполнение. Я считаю, что делаю небольшую ошибку в своем XML.
Прошу вас предоставить любую информацию, которая поможет мне решить эту проблему как можно скорее.
Благодарим за помощь.
БНК. Да, у меня есть следующий код, добавленный в мой метод on_create. toolbar1 = (панель инструментов) findViewById (R.id.toolbar1); setSupportActionBar (панель инструментов1); – Alok
напишите свой AndroidManifest.xml для получения дополнительной информации. – BNK
Попробуйте создать новый «пустой» проект (не «пустой» проект) в AS 1.4, чтобы проверить, имеет ли он панель действий или нет – BNK