android - 在运行 Android 11 的设备上,targetSdkVersion 22 底部出现黑色空间

标签 android android-layout user-interface android-appcompat targetsdkversion

搭载 Android 11 的全新 Motorola Defy 上出现以下错误:

当我的 targetSdkVersion 为 22 时,我的应用程序中有一个奇怪的黑色底栏,如果我将 24 设置为 targetSdkVersion,该底栏就会消失。

Bug occurs on Motorola Defy with ndroid 11

安装 Android 5 的摩托罗拉 E2 上并未出现该错误。

出于正当理由,我希望留在 targetSdkVersion 22。该应用程序将在我们客户的极少数已知设备上运行。电话被锁定在某种信息亭模式下。 targetSdkVersion 22 不强制执行RuntimePermissions,这使得它非常适合用作信息亭应用程序。

这是精简的build.gradle (:app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 30

    defaultConfig {
        //...
        minSdkVersion 17
        //noinspection ExpiredTargetSdkVersion
        targetSdkVersion 22
        versionCode 140
        versionName "1.4.0 in dev " + new Date().format('yyyy-MM-dd HH:mm:ss')
    }
}

dependencies {

    //We don't plan to switch to AndroidX with our legacy Android apps that were written around API level 19
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:28.0.0'
}

这是精简的 AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="xxxxxxxxxxx">

    <application
        android:name="xxxxx.xxxxApplication"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity
            android:name="xxxxxx.PresetActivity"
            android:configChanges="keyboardHidden|orientation"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateUnchanged" 
            android:launchMode="singleTop">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
       
    </application>
</manifest>

这是精简后的 styles.xml(我只有一个 styles.xml):

<resources xmlns:android="http://schemas.android.com/apk/res/android">

     <!-- Application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    </style>

</resources>

精简的 Activity 代码:

package xxxxxxxxxxx.ui.activity;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import xxxxxxxxx.ui.fragment.PresetFragment;
import android.support.v7.app.AppCompatActivity;

public class PresetActivity extends AppCompatActivity { 

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_container);

        // Add fragment the correct way
        // http://stackoverflow.com/questions/8474104/android-fragment-lifecycle-over-orientation-changes

        Fragment fragment = getSupportFragmentManager().findFragmentById(
                R.id.FragmentContainer);

        if (fragment == null) {

            FragmentTransaction fragmentTransaction = getSupportFragmentManager()
                    .beginTransaction();

            fragmentTransaction.add(R.id.FragmentContainer,
                    new PresetFragment());

            fragmentTransaction.commit();
        }
    }
}

activity_container.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:animateLayoutChanges="true"
    android:background="@color/color_background"
    android:paddingTop="8dp"
    tools:ignore="MergeRootFrame">

    <fragment
        android:id="@+id/status_bar_fragment"
        class="xxx.ui.fragment.StatusBarFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:layout="@layout/fragment_status_bar" />

    <FrameLayout
        android:id="@+id/FragmentContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/status_bar_fragment"
        android:layout_alignRight="@+id/status_bar_fragment"></FrameLayout>
        
        
</RelativeLayout>

最佳答案

系统假定您的应用程序无法处理非标准宽高比并使用 16:9 信箱。

这可以通过 resizeableActivity 来控制:

<activity
    ....
    android:resizeableActivity="true"

如果您不设置它,则如果您的目标是 API 24 或更高版本,则默认值为 true,否则为 false。

关于android - 在运行 Android 11 的设备上,targetSdkVersion 22 底部出现黑色空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72801462/

相关文章:

android - 不是 DRM 文件,正常打开

android - 错误消息 : emulator-arm. exe 已停止工作

android - 字符串资源新行/n 不可能?

c++ - 如何制作 Linux C++ GUI 应用程序

android - 将 Android RelativeLayout 与 Gone Views 相结合

Android - 从 onTouchEvent() 访问成员变量

java - android中的垂直 slider 使用谷歌 Material 库

android dialogs UX 体验 - 一个对话框中的两个 ListView 或微调器

android - 更改文本上的阴影大小

javascript - 如何使用 javascript 更改特定的 css 元素?