搭载 Android 11 的全新 Motorola Defy 上出现以下错误:
当我的 targetSdkVersion
为 22 时,我的应用程序中有一个奇怪的黑色底栏,如果我将 24 设置为 targetSdkVersion
,该底栏就会消失。
安装 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/