Created
May 20, 2015 08:20
-
-
Save wasnot/5d219ee7f03d41bdce72 to your computer and use it in GitHub Desktop.
ロック画面でのDialog表示する時の注意(Theme, windowIsFloatingをtrue) ref: http://qiita.com/wasnot/items/760bd2eb22c214485900
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Panelテーマを継承した場合--> | |
<style name="MyPanelTheme" parent="android:style/Theme.Light.Panel"> | |
<!--重要:この二つが少なくともfalse出ないとロックスクリーンには表示されません--> | |
<item name="android:windowIsFloating">false</item> | |
<item name="android:windowNoDisplay">false</item> | |
</style> | |
<!-- AppCompatなテーマからPanelテーマにする場合--> | |
<style name="AppCompatPanelTheme" parent="style/Theme.AppCompat.Light"> | |
<!--重要:この二つが少なくともfalse出ないとロックスクリーンには表示されません--> | |
<item name="android:windowIsFloating">false</item> | |
<item name="android:windowNoDisplay">false</item> | |
<!--その他Panelテーマにするための例--> | |
<item name="android:windowBackground">@color/transparent</item> | |
<item name="android:colorBackgroundCacheHint">@null</item> | |
<item name="android:windowFrame">@null</item> | |
<item name="android:windowContentOverlay">@null</item> | |
<item name="android:windowAnimationStyle">@null</item> | |
<item name="android:windowIsTranslucent">true</item> | |
<item name="android:windowNoTitle">true</item> | |
<item name="android:windowDisablePreview">true</item> | |
<item name="android:backgroundDimEnabled">true</item> | |
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
… | |
// ロック画面解除とロック画面上に表示するフラグを追加します。 | |
getWindow().addFlags( | |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | |
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); | |
// もしロック中で画面を点灯させたい場合はさらにフラグを追加します。 | |
if (makeScreenOn) { | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); | |
} | |
… | |
// 適宜ダイアログを表示してください。 | |
MyDialogFragment.show(this); | |
} | |
@Override | |
protected void onResume() { | |
super.onResume(); | |
… | |
// ロックされている時に起動中のアプリ画面が見えてしまうのが嫌なので壁紙を表示して擬似的にロック画面のように見せる。 | |
KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); | |
if (km.inKeyguardRestrictedInputMode()) { | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER); | |
} else { | |
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER); | |
} | |
… | |
} | |
… |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment