簡體   English   中英

在裝有 Android 11 的設備上,帶有 targetSdkVersion 22 的底部有黑色空間

[英]Black space at the bottom with targetSdkVersion 22 on a device with Android 11

帶有 Android 11 的相當新的摩托羅拉 Defy 出現以下錯誤:

當我的targetSdkVersion為 22 時,我的應用程序中有一個奇怪的黑色底欄,如果我將 24 設置為targetSdkVersion消失。

帶有 android 11 的摩托羅拉 Defy 出現錯誤

該錯誤不會出現在我的裝有 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>

精簡活動代碼:

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。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM