0
我試圖構建一個測試應用程序,只是在發生配置更改時中繼Toast消息。 (以及它應該做什麼,它不起作用)最終目的是檢測用戶是否將平板電腦放入鍵盤底座或將其從其中移除。我的清單和主要活動在下面..我認爲這個代碼會觸發烤麪包,當平板電腦的配置更改爲uiMode或外部鍵盤時..但是當我停靠/取消停放時,沒有任何事情發生..請幫助檢測uiMode或鍵盤變化android
我的清單:
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk android:minSdkVersion="12" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".UiModeTestActivity"
android:configChanges="keyboard|uiMode"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
我的Java:
package com.eliddell;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.widget.Toast;
public class UiModeTestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Toast.makeText(getApplicationContext(), "new config:"+newConfig, Toast.LENGTH_LONG).show();
}
}