android:configChanges="keyboardHidden|orientation" 无效

本文探讨了Android应用中不同屏幕方向变化的处理方式。通过对比android:configChanges属性的设置,发现使用keyboardHidden|orientation无法触发onConfigurationChanged回调,而更改为screenSize|orientation则可以正常响应。这为开发者提供了关于如何正确配置应用以适应不同屏幕方向的重要参考。

测试机型:android 5.1

使用android:configChanges="keyboardHidden|orientation"时转屏没有进入以下回调中:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    Log.i(TAG, "onConfigurationChanged called.");
    switch (newConfig.orientation) {
        case Configuration.ORIENTATION_PORTRAIT:
            Log.i(TAG,"pp");
            setContentView(R.layout.op);
            break;
        case Configuration.ORIENTATION_LANDSCAPE:
            Log.i(TAG,"ll");
            setContentView(R.layout.ol);
            break;
    }
}


改成android:configChanges="screenSize|orientation"后,可以进入回调!

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:installLocation="preferExternal"> <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" /> <uses-permission android:name="android.permission.NFC" /> <uses-feature android:name="android.hardware.nfc.hce" android:required="false" /> <uses-feature android:name="android.hardware.nfc" android:required="false" /> <application android:theme="@style/UnityThemeSelector" android:icon="@drawable/app_icon" android:label="@string/app_name" android:hardwareAccelerated="true"> <activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <!-- 添加NFC处理 --> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="myapp" /> </intent-filter> <!-- 添加深度链接处理 --> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="xl" android:host="goods" android:port="8888" android:pathPrefix="/goodsDetail" /> </intent-filter> </activity> </application> </manifest> 这是我现在的xml文件,我的应用包名为com.example.text 我该怎么更改,并使用什么URL去启动应用并传递数据
08-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值