Android - Activity Home/向上箭头在 SDK 24 中有额外的填充/边距

标签 android android-layout android-actionbar android-sdk-tools android-actionbar-compat

我刚刚将我的应用从使用 SDK 23 更新到 SDK 24。

我的 Activity 出现了一个问题,这些 Activity 显示了向上/主页箭头(即 getSupportActionBar().setDisplayHomeAsUpEnabled(true)),因为现在向上之间有额外的(不需要的)空间箭头和 Activity 标题。

对于没有向上箭头的 Activity , Activity 标题与之前的位置完全相同,这表明额外的填充/边距与向上箭头相关联,而不是与 Activity 标题相关联。

我的问题是如何更改布局,使其在 SDK 24 中看起来与在 SDK 23 中相同?

向上箭头和使用 SDK 23 的标题之间的小间隙: Small gap between Up arrow and title using SDK 23

使用 SDK 24 的向上箭头和标题之间存在较大(不需要的)间隙: Large (unwanted) gap between Up arrow and title using SDK 24

这是我的旧 build.gradle (SDK 23):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.example.myapp"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 42
        versionName "0.42"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.google.android.gms:play-services-vision:9.0.2'
    compile 'ch.acra:acra:4.7.0'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'com.android.support:recyclerview-v7:23.4.0'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:support-v13:23.4.0'
    compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
    compile 'com.google.zxing:core:3.2.1'
}

这是新的 build.gradle (SDK 24):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.example.myapp"
        minSdkVersion 19
        targetSdkVersion 24
        versionCode 42
        versionName "0.42"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.google.android.gms:play-services-vision:9.0.2'
    compile 'ch.acra:acra:4.7.0'
    compile 'com.android.support:support-v4:24.0.0'
    compile 'com.android.support:recyclerview-v7:24.0.0'
    compile 'com.android.support:appcompat-v7:24.0.0'
    compile 'com.android.support:design:24.0.0'
    compile 'com.android.support:support-v13:24.0.0'
    compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
    compile 'com.google.zxing:core:3.2.1'
}

最佳答案

这已在 Android 问题跟踪器中得到解答。链接是:

https://code.google.com/p/android/issues/detail?id=213826

app:contentInsetStartWithNavigation="0dp" 添加到工具栏 View 。

关于Android - Activity Home/向上箭头在 SDK 24 中有额外的填充/边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37859807/

相关文章:

java - 创建我的第一个应用程序,对主要 Activity 和 fragment 感到困惑

android - 如何在android中的TTS中的单词之间暂停或间隔

android - 如何有一个圆形的 TextView

java - 如何获取单击 View 的同级 View ?

android - 如何在 Android 中更改 ActionMode 背景颜色

java - 图书馆 |安卓|我可以在简单游戏中使用非 pow2 纹理吗?

java - SharedPreferences 提交后不保存

android - 以编程方式在相对布局中定位按钮

android - 如何创建适用于深色和浅色主题的 Android 操作栏?

android - 从 SettingActivity 返回到主 Activity