java - android.support.v7.widget.Toolbar 在棉花糖设备上无法正常工作

标签 java android android-toolbar android-6.0-marshmallow

这就是我想要的:

enter image description here

这就是我得到的:

enter image description here

这个问题出现在 api 23 上。在 22 或 21 上,它给出的结果如第一张图片所示。

我的build.gradle是:

apply plugin: 'com.android.application'


android {
compileSdkVersion 22
buildToolsVersion '22.0.1'

defaultConfig {
    applicationId "com.example.bob"
    minSdkVersion 15
    targetSdkVersion 22
    versionCode 3
    versionName "1.0.1"
}
buildTypes {
    release {
        minifyEnabled false
    }
}
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
compile files('libs/android-query-full.0.26.7.jar')
compile files('libs/android-async-http-1.4.4.jar')
compile 'com.google.android.gms:play-services-gcm:7.8.0'
compile 'com.google.android.gms:play-services-ads:7.8.0'
compile 'com.android.support:support-v4:22.2.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:design:22.2.0'
compile'com.github.wrdlbrnft:sorted-list-adapter:0.1.0.5'
compile ('jp.wasabeef:recyclerview-animators:2.2.3'){
    exclude module: 'appcompat-v7'
}
}

我的 android 布局 xml 是:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout       
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".SongList">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay"/>
    <!--
        app:layout_scrollFlags="scroll|enterAlways"/>
        -->

</android.support.design.widget.AppBarLayout>

<include layout="@layout/song_list" />

</android.support.design.widget.CoordinatorLayout>

并在java文件中设置工具栏:

setContentView(R.layout.activity_songlist);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

我不想升级编译和targetsdk版本bcz,那么我必须为 list 中指定的每个权限添加运行时权限方法。

最佳答案

尝试在AppBarLayout中添加这一行:

android:fitsSystemWindows="true"

并将其从 CoordinatorLayout 中删除。

关于java - android.support.v7.widget.Toolbar 在棉花糖设备上无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39332720/

相关文章:

java - 使用 String name() 声明实现 Java 接口(interface)的 Kotlin 枚举

java - 是否可以更改 java 中线程或 jvm 实例的当前时间?

java - 为什么在隐藏 fragment 时有时会得到堆栈跟踪?

java - 对封闭类实例的内部类引用为空

Android setLogo 没有放在 Action Bar 的中心

java - IntelliJ错误打开zip文件或JAR list 丢失

java - 带有 MS Access 的 JDBC 中的 "architecture mismatch between the Driver and Application"

android - Kotlin扩展函数: unresolved reference

android - SearchView 隐藏 Toolbar 中的其他 Label

android-tabs - 使用支持库 v7 :21 with Toolbar in Android Developer Tools for existing project 添加滑动标签