Created
May 20, 2015 11:16
-
-
Save wasnot/ca2246a2c544e5e91085 to your computer and use it in GitHub Desktop.
Dialogを使った通知 ref: http://qiita.com/wasnot/items/6ad7a6b1e178ea21d436
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
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> |
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
public void show(){ | |
// Viewをinflateする。 | |
mView = LayoutInflater.from(mContext).inflate(R.layout.view, null); | |
// 適宜Viewをカスタマイズする | |
// Windowに追加するときのLayoutParamsをつくる | |
WindowManager.LayoutParams params = new WindowManager.LayoutParams(); | |
params.width = WindowManager.LayoutParams.MATCH_PARENT; | |
params.height = WindowManager.LayoutParams.MATCH_PARENT; | |
params.gravity = Gravity.CENTER; | |
// どの層にaddするか。追加できない層もたくさんある。 | |
params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; | |
params.format = PixelFormat.TRANSLUCENT; | |
// Dialogのアニメーションにするとそれっぽいです。 | |
params.windowAnimations = android.R.style.Animation_Dialog; | |
// 必要に応じていろんなflagを設定します。入らなければ削ります。 | |
params.flags = WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | |
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | |
| WindowManager.LayoutParams.FLAG_DIM_BEHIND | |
| WindowManager.LayoutParams.FLAG_FULLSCREEN; | |
// 背景に影を表示してそれっぽくします。 | |
params.dimAmount = 0.6f; | |
// WindowManagerを使ってViewを追加する | |
mWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE); | |
mWindowManager.addView(mView, params); | |
} | |
public void dismiss(){ | |
// removeでViewの表示をけす。 | |
mWindowManager.removeView(mView); | |
} |
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
<style name="AppPanelTheme" parent="style/Theme.AppCompat"> | |
// android:style/Theme.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> | |
// こちらはTheme.Panelだとtrueですが、falseでもいいです。 | |
// trueだとロック画面に表示できません(不要かもしれませんが) | |
<!--<item name="android:windowIsFloating">true</item>--> | |
<item name="android:windowIsFloating">false</item> | |
<item name="android:backgroundDimEnabled">true</item> | |
<item name="android:windowIsTranslucent">true</item> | |
<item name="android:windowNoTitle">true</item> | |
// これは書かれていませんが、追加してもいいかもしれません | |
<item name="android:windowDisablePreview">true</item> | |
<item name="android:windowNoDisplay">false</item> | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment